R600: Begin private memory at the second GPR.
[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
17 ; SI-CHECK: V_MOVRELD
18 ; SI-CHECK: S_CBRANCH
19 ; SI-CHECK: V_READFIRSTLANE
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: MOVA_INT
120
121 ; SI-CHECK: V_MOV_B32_e32 v{{[0-9]}}, 65536
122 ; SI-CHECK: V_MOVRELS_B32_e32
123 define void @short_array(i32 addrspace(1)* %out, i32 %index) {
124 entry:
125   %0 = alloca [2 x i16]
126   %1 = getelementptr [2 x i16]* %0, i32 0, i32 0
127   %2 = getelementptr [2 x i16]* %0, i32 0, i32 1
128   store i16 0, i16* %1
129   store i16 1, i16* %2
130   %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
131   %4 = load i16* %3
132   %5 = sext i16 %4 to i32
133   store i32 %5, i32 addrspace(1)* %out
134   ret void
135 }
136
137 ; FUNC-LABEL: @char_array
138
139 ; R600-CHECK: OR_INT {{\** *}}T{{[0-9]\.[XYZW]}}, {{[PVT0-9]+\.[XYZW]}}, literal
140 ; R600-CHECK: 256
141 ; R600-CHECK: MOVA_INT
142
143 ; SI-CHECK: V_OR_B32_e32 v{{[0-9]}}, 256
144 ; SI-CHECK: V_MOVRELS_B32_e32
145 define void @char_array(i32 addrspace(1)* %out, i32 %index) {
146 entry:
147   %0 = alloca [2 x i8]
148   %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
149   %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
150   store i8 0, i8* %1
151   store i8 1, i8* %2
152   %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
153   %4 = load i8* %3
154   %5 = sext i8 %4 to i32
155   store i32 %5, i32 addrspace(1)* %out
156   ret void
157
158 }
159
160 ; Make sure we don't overwrite workitem information with private memory
161
162 ; FUNC-LABEL: @work_item_info
163 ; R600-CHECK-NOT: MOV T0.X
164 ; Additional check in case the move ends up in the last slot
165 ; R600-CHECK-NOT: MOV * TO.X
166
167 ; SI-CHECK-NOT: V_MOV_B32_e{{(32|64)}} v0
168 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
169 entry:
170   %0 = alloca [2 x i32]
171   %1 = getelementptr [2 x i32]* %0, i32 0, i32 0
172   %2 = getelementptr [2 x i32]* %0, i32 0, i32 1
173   store i32 0, i32* %1
174   store i32 1, i32* %2
175   %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
176   %4 = load i32* %3
177   %5 = call i32 @llvm.r600.read.tidig.x()
178   %6 = add i32 %4, %5
179   store i32 %6, i32 addrspace(1)* %out
180   ret void
181 }
182
183 declare i32 @llvm.r600.read.tidig.x() nounwind readnone