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
4 ; This test checks that uses and defs of the AR register happen in the same
7 ; FUNC-LABEL: @mova_same_clause
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
16 ; SI-CHECK: V_READFIRSTLANE
19 ; SI-CHECK: V_READFIRSTLANE
22 define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
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
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.
46 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
49 ; FUNC-LABEL: @multiple_structs
50 ; R600-CHECK-NOT: MOVA_INT
51 ; SI-CHECK-NOT: V_MOVREL
52 %struct.point = type { i32, i32 }
54 define void @multiple_structs(i32 addrspace(1)* %out) {
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
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
79 ; FUNC-LABEL: @direct_loop
80 ; R600-CHECK-NOT: MOVA_INT
81 ; SI-CHECK-NOT: V_MOVREL
83 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
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
97 %inc = phi i32 [0, %entry], [%count, %for.body]
98 %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
100 %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
101 %y = load i32* %y_ptr
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
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
115 ; FUNC-LABEL: @short_array
117 ; R600-CHECK: MOV {{\** *}}T{{[0-9]\.[XYZW]}}, literal
120 ; R600-CHECK: MOVA_INT
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) {
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
131 %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
133 %5 = sext i16 %4 to i32
134 store i32 %5, i32 addrspace(1)* %out
138 ; FUNC-LABEL: @char_array
140 ; R600-CHECK: OR_INT {{\** *}}T{{[0-9]\.[XYZW]}}, {{[PVT0-9]+\.[XYZW]}}, literal
143 ; R600-CHECK-NEXT: MOVA_INT
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) {
150 %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
151 %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
154 %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
156 %5 = sext i8 %4 to i32
157 store i32 %5, i32 addrspace(1)* %out
162 ; Make sure we don't overwrite workitem information with private memory
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
169 ; SI-CHECK-NOT: V_MOV_B32_e{{(32|64)}} v0
170 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
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
177 %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
179 %5 = call i32 @llvm.r600.read.tidig.x()
181 store i32 %6, i32 addrspace(1)* %out
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) {
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
204 %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
205 %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
209 %12 = sext i8 %11 to i32
210 store i32 %12, i32 addrspace(1)* %out
216 declare i32 @llvm.r600.read.tidig.x() nounwind readnone