blob: 6543ab7a59742755e3bd8b9a359310b17238ed76 [file] [log] [blame]
Tom Stellarde9373602014-01-22 19:24:14 +00001; 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
Tom Stellardaad53762013-06-05 03:43:06 +00003
4; This test checks that uses and defs of the AR register happen in the same
5; instruction clause.
6
Tom Stellarde9373602014-01-22 19:24:14 +00007; FUNC-LABEL: @mova_same_clause
8
Tom Stellard81d871d2013-11-13 23:36:50 +00009; 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
Tom Stellardaad53762013-06-05 03:43:06 +000015
Tom Stellardfbe435d2014-03-17 17:03:51 +000016; SI-CHECK: V_READFIRSTLANE_B32 vcc_lo
Tom Stellard81d871d2013-11-13 23:36:50 +000017; SI-CHECK: V_MOVRELD
18; SI-CHECK: S_CBRANCH
Tom Stellardfbe435d2014-03-17 17:03:51 +000019; SI-CHECK: V_READFIRSTLANE_B32 vcc_lo
Tom Stellard81d871d2013-11-13 23:36:50 +000020; SI-CHECK: V_MOVRELD
21; SI-CHECK: S_CBRANCH
Tom Stellardaad53762013-06-05 03:43:06 +000022define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
23entry:
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}
Tom Stellardd7458372013-06-07 20:52:05 +000041
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
Tom Stellarde9373602014-01-22 19:24:14 +000049; FUNC-LABEL: @multiple_structs
Tom Stellard81d871d2013-11-13 23:36:50 +000050; R600-CHECK-NOT: MOVA_INT
Tom Stellard81d871d2013-11-13 23:36:50 +000051; SI-CHECK-NOT: V_MOVREL
Tom Stellardd7458372013-06-07 20:52:05 +000052%struct.point = type { i32, i32 }
53
54define void @multiple_structs(i32 addrspace(1)* %out) {
55entry:
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}
Tom Stellard26a3b672013-10-22 18:19:10 +000074
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
Tom Stellarde9373602014-01-22 19:24:14 +000079; FUNC-LABEL: @direct_loop
Tom Stellard81d871d2013-11-13 23:36:50 +000080; R600-CHECK-NOT: MOVA_INT
Tom Stellard81d871d2013-11-13 23:36:50 +000081; SI-CHECK-NOT: V_MOVREL
Tom Stellard26a3b672013-10-22 18:19:10 +000082
83define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
84entry:
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
96for.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
108for.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}
Tom Stellarde9373602014-01-22 19:24:14 +0000114
115; FUNC-LABEL: @short_array
116
117; R600-CHECK: MOV {{\** *}}T{{[0-9]\.[XYZW]}}, literal
118; R600-CHECK: 65536
Tom Stellard476437c2014-01-22 19:24:24 +0000119; R600-CHECK: *
Tom Stellarde9373602014-01-22 19:24:14 +0000120; R600-CHECK: MOVA_INT
121
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000122; SI-CHECK: V_MOV_B32_e32 v{{[0-9]}}, 0x10000
Tom Stellarde9373602014-01-22 19:24:14 +0000123; SI-CHECK: V_MOVRELS_B32_e32
124define void @short_array(i32 addrspace(1)* %out, i32 %index) {
125entry:
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
Tom Stellard476437c2014-01-22 19:24:24 +0000142; R600-CHECK: *
143; R600-CHECK-NEXT: MOVA_INT
Tom Stellarde9373602014-01-22 19:24:14 +0000144
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000145; SI-CHECK: V_OR_B32_e32 v{{[0-9]}}, 0x100
Tom Stellarde9373602014-01-22 19:24:14 +0000146; SI-CHECK: V_MOVRELS_B32_e32
147define void @char_array(i32 addrspace(1)* %out, i32 %index) {
148entry:
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}
Tom Stellard27982b12014-01-22 19:24:19 +0000161
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
170define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
171entry:
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
Tom Stellard598f3942014-01-22 19:24:23 +0000185; 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
190define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
191entry:
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
Tom Stellard27982b12014-01-22 19:24:19 +0000216declare i32 @llvm.r600.read.tidig.x() nounwind readnone