1; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck --check-prefix=EG -check-prefix=FUNC %s
2; RUN: llc -march=amdgcn -mcpu=verde -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC %s
3; RUN: llc -march=amdgcn -mcpu=verde -mattr=+promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC %s
4; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC %s
5; RUN: llc -march=amdgcn -mcpu=tonga -mattr=+promote-alloca -verify-machineinstrs < %s | FileCheck -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC %s
6
7; FUNC-LABEL: {{^}}vector_read:
8; EG: MOV
9; EG: MOV
10; EG: MOV
11; EG: MOV
12; EG: MOVA_INT
13define void @vector_read(i32 addrspace(1)* %out, i32 %index) {
14entry:
15  %0 = alloca [4 x i32]
16  %x = getelementptr [4 x i32]* %0, i32 0, i32 0
17  %y = getelementptr [4 x i32]* %0, i32 0, i32 1
18  %z = getelementptr [4 x i32]* %0, i32 0, i32 2
19  %w = getelementptr [4 x i32]* %0, i32 0, i32 3
20  store i32 0, i32* %x
21  store i32 1, i32* %y
22  store i32 2, i32* %z
23  store i32 3, i32* %w
24  %1 = getelementptr [4 x i32]* %0, i32 0, i32 %index
25  %2 = load i32* %1
26  store i32 %2, i32 addrspace(1)* %out
27  ret void
28}
29
30; FUNC-LABEL: {{^}}vector_write:
31; EG: MOV
32; EG: MOV
33; EG: MOV
34; EG: MOV
35; EG: MOVA_INT
36; EG: MOVA_INT
37define void @vector_write(i32 addrspace(1)* %out, i32 %w_index, i32 %r_index) {
38entry:
39  %0 = alloca [4 x i32]
40  %x = getelementptr [4 x i32]* %0, i32 0, i32 0
41  %y = getelementptr [4 x i32]* %0, i32 0, i32 1
42  %z = getelementptr [4 x i32]* %0, i32 0, i32 2
43  %w = getelementptr [4 x i32]* %0, i32 0, i32 3
44  store i32 0, i32* %x
45  store i32 0, i32* %y
46  store i32 0, i32* %z
47  store i32 0, i32* %w
48  %1 = getelementptr [4 x i32]* %0, i32 0, i32 %w_index
49  store i32 1, i32* %1
50  %2 = getelementptr [4 x i32]* %0, i32 0, i32 %r_index
51  %3 = load i32* %2
52  store i32 %3, i32 addrspace(1)* %out
53  ret void
54}
55
56; This test should be optimize to:
57; store i32 0, i32 addrspace(1)* %out
58; FUNC-LABEL: {{^}}bitcast_gep:
59; EG: STORE_RAW
60define void @bitcast_gep(i32 addrspace(1)* %out, i32 %w_index, i32 %r_index) {
61entry:
62  %0 = alloca [4 x i32]
63  %x = getelementptr [4 x i32]* %0, i32 0, i32 0
64  %y = getelementptr [4 x i32]* %0, i32 0, i32 1
65  %z = getelementptr [4 x i32]* %0, i32 0, i32 2
66  %w = getelementptr [4 x i32]* %0, i32 0, i32 3
67  store i32 0, i32* %x
68  store i32 0, i32* %y
69  store i32 0, i32* %z
70  store i32 0, i32* %w
71  %1 = getelementptr [4 x i32]* %0, i32 0, i32 1
72  %2 = bitcast i32* %1 to [4 x i32]*
73  %3 = getelementptr [4 x i32]* %2, i32 0, i32 0
74  %4 = load i32* %3
75  store i32 %4, i32 addrspace(1)* %out
76  ret void
77}
78