R600/SI: Use correct dest register class for V_READFIRSTLANE_B32
[oota-llvm.git] / test / CodeGen / R600 / private-memory.ll
1 ; RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck %s --check-prefix=R600-CHECK --check-prefix=FUNC
2 ; RUN: llc < %s -march=r600 -mcpu=SI | FileCheck %s --check-prefix=SI-CHECK --check-prefix=FUNC
3
4 ; This test checks that uses and defs of the AR register happen in the same
5 ; instruction clause.
6
7 ; FUNC-LABEL: @mova_same_clause
8
9 ; R600-CHECK: MOVA_INT
10 ; R600-CHECK-NOT: ALU clause
11 ; R600-CHECK: 0 + AR.x
12 ; R600-CHECK: MOVA_INT
13 ; R600-CHECK-NOT: ALU clause
14 ; R600-CHECK: 0 + AR.x
15
16 ; SI-CHECK: V_READFIRSTLANE_B32 vcc_lo
17 ; SI-CHECK: V_MOVRELD
18 ; SI-CHECK: S_CBRANCH
19 ; SI-CHECK: V_READFIRSTLANE_B32 vcc_lo
20 ; SI-CHECK: V_MOVRELD
21 ; SI-CHECK: S_CBRANCH
22 define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
23 entry:
24   %stack = alloca [5 x i32], align 4
25   %0 = load i32 addrspace(1)* %in, align 4
26   %arrayidx1 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %0
27   store i32 4, i32* %arrayidx1, align 4
28   %arrayidx2 = getelementptr inbounds i32 addrspace(1)* %in, i32 1
29   %1 = load i32 addrspace(1)* %arrayidx2, align 4
30   %arrayidx3 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %1
31   store i32 5, i32* %arrayidx3, align 4
32   %arrayidx10 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 0
33   %2 = load i32* %arrayidx10, align 4
34   store i32 %2, i32 addrspace(1)* %out, align 4
35   %arrayidx12 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 1
36   %3 = load i32* %arrayidx12
37   %arrayidx13 = getelementptr inbounds i32 addrspace(1)* %out, i32 1
38   store i32 %3, i32 addrspace(1)* %arrayidx13
39   ret void
40 }
41
42 ; This test checks that the stack offset is calculated correctly for structs.
43 ; All register loads/stores should be optimized away, so there shouldn't be
44 ; any MOVA instructions.
45 ;
46 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
47 ; this.
48
49 ; FUNC-LABEL: @multiple_structs
50 ; R600-CHECK-NOT: MOVA_INT
51 ; SI-CHECK-NOT: V_MOVREL
52 %struct.point = type { i32, i32 }
53
54 define void @multiple_structs(i32 addrspace(1)* %out) {
55 entry:
56   %a = alloca %struct.point
57   %b = alloca %struct.point
58   %a.x.ptr = getelementptr %struct.point* %a, i32 0, i32 0
59   %a.y.ptr = getelementptr %struct.point* %a, i32 0, i32 1
60   %b.x.ptr = getelementptr %struct.point* %b, i32 0, i32 0
61   %b.y.ptr = getelementptr %struct.point* %b, i32 0, i32 1
62   store i32 0, i32* %a.x.ptr
63   store i32 1, i32* %a.y.ptr
64   store i32 2, i32* %b.x.ptr
65   store i32 3, i32* %b.y.ptr
66   %a.indirect.ptr = getelementptr %struct.point* %a, i32 0, i32 0
67   %b.indirect.ptr = getelementptr %struct.point* %b, i32 0, i32 0
68   %a.indirect = load i32* %a.indirect.ptr
69   %b.indirect = load i32* %b.indirect.ptr
70   %0 = add i32 %a.indirect, %b.indirect
71   store i32 %0, i32 addrspace(1)* %out
72   ret void
73 }
74
75 ; Test direct access of a private array inside a loop.  The private array
76 ; loads and stores should be lowered to copies, so there shouldn't be any
77 ; MOVA instructions.
78
79 ; FUNC-LABEL: @direct_loop
80 ; R600-CHECK-NOT: MOVA_INT
81 ; SI-CHECK-NOT: V_MOVREL
82
83 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
84 entry:
85   %prv_array_const = alloca [2 x i32]
86   %prv_array = alloca [2 x i32]
87   %a = load i32 addrspace(1)* %in
88   %b_src_ptr = getelementptr i32 addrspace(1)* %in, i32 1
89   %b = load i32 addrspace(1)* %b_src_ptr
90   %a_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
91   store i32 %a, i32* %a_dst_ptr
92   %b_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 1
93   store i32 %b, i32* %b_dst_ptr
94   br label %for.body
95
96 for.body:
97   %inc = phi i32 [0, %entry], [%count, %for.body]
98   %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
99   %x = load i32* %x_ptr
100   %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
101   %y = load i32* %y_ptr
102   %xy = add i32 %x, %y
103   store i32 %xy, i32* %y_ptr
104   %count = add i32 %inc, 1
105   %done = icmp eq i32 %count, 4095
106   br i1 %done, label %for.end, label %for.body
107
108 for.end:
109   %value_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
110   %value = load i32* %value_ptr
111   store i32 %value, i32 addrspace(1)* %out
112   ret void
113 }
114
115 ; FUNC-LABEL: @short_array
116
117 ; R600-CHECK: MOV {{\** *}}T{{[0-9]\.[XYZW]}}, literal
118 ; R600-CHECK: 65536
119 ; R600-CHECK: *
120 ; R600-CHECK: MOVA_INT
121
122 ; SI-CHECK: V_MOV_B32_e32 v{{[0-9]}}, 65536
123 ; SI-CHECK: V_MOVRELS_B32_e32
124 define void @short_array(i32 addrspace(1)* %out, i32 %index) {
125 entry:
126   %0 = alloca [2 x i16]
127   %1 = getelementptr [2 x i16]* %0, i32 0, i32 0
128   %2 = getelementptr [2 x i16]* %0, i32 0, i32 1
129   store i16 0, i16* %1
130   store i16 1, i16* %2
131   %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
132   %4 = load i16* %3
133   %5 = sext i16 %4 to i32
134   store i32 %5, i32 addrspace(1)* %out
135   ret void
136 }
137
138 ; FUNC-LABEL: @char_array
139
140 ; R600-CHECK: OR_INT {{\** *}}T{{[0-9]\.[XYZW]}}, {{[PVT0-9]+\.[XYZW]}}, literal
141 ; R600-CHECK: 256
142 ; R600-CHECK: *
143 ; R600-CHECK-NEXT: MOVA_INT
144
145 ; SI-CHECK: V_OR_B32_e32 v{{[0-9]}}, 256
146 ; SI-CHECK: V_MOVRELS_B32_e32
147 define void @char_array(i32 addrspace(1)* %out, i32 %index) {
148 entry:
149   %0 = alloca [2 x i8]
150   %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
151   %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
152   store i8 0, i8* %1
153   store i8 1, i8* %2
154   %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
155   %4 = load i8* %3
156   %5 = sext i8 %4 to i32
157   store i32 %5, i32 addrspace(1)* %out
158   ret void
159
160 }
161
162 ; Make sure we don't overwrite workitem information with private memory
163
164 ; FUNC-LABEL: @work_item_info
165 ; R600-CHECK-NOT: MOV T0.X
166 ; Additional check in case the move ends up in the last slot
167 ; R600-CHECK-NOT: MOV * TO.X
168
169 ; SI-CHECK-NOT: V_MOV_B32_e{{(32|64)}} v0
170 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
171 entry:
172   %0 = alloca [2 x i32]
173   %1 = getelementptr [2 x i32]* %0, i32 0, i32 0
174   %2 = getelementptr [2 x i32]* %0, i32 0, i32 1
175   store i32 0, i32* %1
176   store i32 1, i32* %2
177   %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
178   %4 = load i32* %3
179   %5 = call i32 @llvm.r600.read.tidig.x()
180   %6 = add i32 %4, %5
181   store i32 %6, i32 addrspace(1)* %out
182   ret void
183 }
184
185 ; Test that two stack objects are not stored in the same register
186 ; The second stack object should be in T3.X
187 ; FUNC-LABEL: @no_overlap
188 ; R600-CHECK: MOV {{\** *}}T3.X
189 ; SI-CHECK: V_MOV_B32_e32 v3
190 define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
191 entry:
192   %0 = alloca [3 x i8], align 1
193   %1 = alloca [2 x i8], align 1
194   %2 = getelementptr [3 x i8]* %0, i32 0, i32 0
195   %3 = getelementptr [3 x i8]* %0, i32 0, i32 1
196   %4 = getelementptr [3 x i8]* %0, i32 0, i32 2
197   %5 = getelementptr [2 x i8]* %1, i32 0, i32 0
198   %6 = getelementptr [2 x i8]* %1, i32 0, i32 1
199   store i8 0, i8* %2
200   store i8 1, i8* %3
201   store i8 2, i8* %4
202   store i8 1, i8* %5
203   store i8 0, i8* %6
204   %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
205   %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
206   %9 = load i8* %7
207   %10 = load i8* %8
208   %11 = add i8 %9, %10
209   %12 = sext i8 %11 to i32
210   store i32 %12, i32 addrspace(1)* %out
211   ret void
212 }
213
214
215
216 declare i32 @llvm.r600.read.tidig.x() nounwind readnone