R600: Add a testcase for sext_in_reg I missed.
[oota-llvm.git] / test / CodeGen / R600 / sext-in-reg.ll
1 ; RUN: llc < %s -march=r600 -mcpu=SI | FileCheck -check-prefix=SI -check-prefix=FUNC %s
2 ; RUN: llc < %s -march=r600 -mcpu=cypress | FileCheck -check-prefix=EG -check-prefix=FUNC %s
3
4 ; FUNC-LABEL: @sext_in_reg_i1_i32
5 ; SI: S_LOAD_DWORD [[ARG:s[0-9]+]],
6 ; SI: V_BFE_I32 [[EXTRACT:v[0-9]+]], [[ARG]], 0, 1
7 ; SI: BUFFER_STORE_DWORD [[EXTRACT]],
8
9 ; EG: BFE_INT
10 define void @sext_in_reg_i1_i32(i32 addrspace(1)* %out, i32 %in) {
11   %shl = shl i32 %in, 31
12   %sext = ashr i32 %shl, 31
13   store i32 %sext, i32 addrspace(1)* %out
14   ret void
15 }
16
17 ; FUNC-LABEL: @sext_in_reg_i8_to_i32
18 ; SI: S_ADD_I32 [[VAL:s[0-9]+]],
19 ; SI: V_BFE_I32 [[EXTRACT:v[0-9]+]], [[VAL]], 0, 8
20 ; SI: BUFFER_STORE_DWORD [[EXTRACT]],
21
22 ; EG: BFE_INT
23 define void @sext_in_reg_i8_to_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
24   %c = add i32 %a, %b ; add to prevent folding into extload
25   %shl = shl i32 %c, 24
26   %ashr = ashr i32 %shl, 24
27   store i32 %ashr, i32 addrspace(1)* %out, align 4
28   ret void
29 }
30
31 ; FUNC-LABEL: @sext_in_reg_i16_to_i32
32 ; SI: S_ADD_I32 [[VAL:s[0-9]+]],
33 ; SI: V_BFE_I32 [[EXTRACT:v[0-9]+]], [[VAL]], 0, 16
34 ; SI: BUFFER_STORE_DWORD [[EXTRACT]],
35
36 ; EG: BFE_INT
37 define void @sext_in_reg_i16_to_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
38   %c = add i32 %a, %b ; add to prevent folding into extload
39   %shl = shl i32 %c, 16
40   %ashr = ashr i32 %shl, 16
41   store i32 %ashr, i32 addrspace(1)* %out, align 4
42   ret void
43 }
44
45 ; FUNC-LABEL: @sext_in_reg_i8_to_v1i32
46 ; SI: S_ADD_I32 [[VAL:s[0-9]+]],
47 ; SI: V_BFE_I32 [[EXTRACT:v[0-9]+]], [[VAL]], 0, 8
48 ; SI: BUFFER_STORE_DWORD [[EXTRACT]],
49
50 ; EG: BFE_INT
51 define void @sext_in_reg_i8_to_v1i32(<1 x i32> addrspace(1)* %out, <1 x i32> %a, <1 x i32> %b) nounwind {
52   %c = add <1 x i32> %a, %b ; add to prevent folding into extload
53   %shl = shl <1 x i32> %c, <i32 24>
54   %ashr = ashr <1 x i32> %shl, <i32 24>
55   store <1 x i32> %ashr, <1 x i32> addrspace(1)* %out, align 4
56   ret void
57 }
58
59 ; FUNC-LABEL: @sext_in_reg_i8_to_i64
60 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
61 ; SI: V_ASHRREV_I32_e32 {{v[0-9]+}}, 31,
62 ; SI: BUFFER_STORE_DWORD
63
64 ; EG: BFE_INT
65 ; EG: ASHR
66 define void @sext_in_reg_i8_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
67   %c = add i64 %a, %b
68   %shl = shl i64 %c, 56
69   %ashr = ashr i64 %shl, 56
70   store i64 %ashr, i64 addrspace(1)* %out, align 8
71   ret void
72 }
73
74 ; FUNC-LABEL: @sext_in_reg_i16_to_i64
75 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 16
76 ; SI: V_ASHRREV_I32_e32 {{v[0-9]+}}, 31,
77 ; SI: BUFFER_STORE_DWORD
78
79 ; EG: BFE_INT
80 ; EG: ASHR
81 define void @sext_in_reg_i16_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
82   %c = add i64 %a, %b
83   %shl = shl i64 %c, 48
84   %ashr = ashr i64 %shl, 48
85   store i64 %ashr, i64 addrspace(1)* %out, align 8
86   ret void
87 }
88
89 ; FUNC-LABEL: @sext_in_reg_i32_to_i64
90 ; SI: S_LOAD_DWORDX2
91 ; SI: S_ADD_I32
92 ; SI-NEXT: S_ADDC_U32
93 ; SI-NEXT: S_ASHR_I32 s{{[0-9]+}}, s{{[0-9]+}}, 31
94 ; SI: BUFFER_STORE_DWORDX2
95 define void @sext_in_reg_i32_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
96   %c = add i64 %a, %b
97   %shl = shl i64 %c, 32
98   %ashr = ashr i64 %shl, 32
99   store i64 %ashr, i64 addrspace(1)* %out, align 8
100   ret void
101 }
102
103 ; This is broken on Evergreen for some reason related to the <1 x i64> kernel arguments.
104 ; XFUNC-LABEL: @sext_in_reg_i8_to_v1i64
105 ; XSI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
106 ; XSI: V_ASHRREV_I32_e32 {{v[0-9]+}}, 31,
107 ; XSI: BUFFER_STORE_DWORD
108 ; XEG: BFE_INT
109 ; XEG: ASHR
110 ; define void @sext_in_reg_i8_to_v1i64(<1 x i64> addrspace(1)* %out, <1 x i64> %a, <1 x i64> %b) nounwind {
111 ;   %c = add <1 x i64> %a, %b
112 ;   %shl = shl <1 x i64> %c, <i64 56>
113 ;   %ashr = ashr <1 x i64> %shl, <i64 56>
114 ;   store <1 x i64> %ashr, <1 x i64> addrspace(1)* %out, align 8
115 ;   ret void
116 ; }
117
118 ; FUNC-LABEL: @sext_in_reg_i1_in_i32_other_amount
119 ; SI-NOT: BFE
120 ; SI: S_LSHL_B32 [[REG:s[0-9]+]], {{s[0-9]+}}, 6
121 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG]], 7
122 ; EG-NOT: BFE
123 define void @sext_in_reg_i1_in_i32_other_amount(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
124   %c = add i32 %a, %b
125   %x = shl i32 %c, 6
126   %y = ashr i32 %x, 7
127   store i32 %y, i32 addrspace(1)* %out
128   ret void
129 }
130
131 ; FUNC-LABEL: @sext_in_reg_v2i1_in_v2i32_other_amount
132 ; SI: S_LSHL_B32 [[REG0:s[0-9]+]], {{s[0-9]}}, 6
133 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG0]], 7
134 ; SI: S_LSHL_B32 [[REG1:s[0-9]+]], {{s[0-9]}}, 6
135 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG1]], 7
136 ; EG-NOT: BFE
137 define void @sext_in_reg_v2i1_in_v2i32_other_amount(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
138   %c = add <2 x i32> %a, %b
139   %x = shl <2 x i32> %c, <i32 6, i32 6>
140   %y = ashr <2 x i32> %x, <i32 7, i32 7>
141   store <2 x i32> %y, <2 x i32> addrspace(1)* %out, align 2
142   ret void
143 }
144
145
146 ; FUNC-LABEL: @sext_in_reg_v2i1_to_v2i32
147 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
148 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
149 ; SI: BUFFER_STORE_DWORDX2
150 ; EG: BFE
151 ; EG: BFE
152 define void @sext_in_reg_v2i1_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
153   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
154   %shl = shl <2 x i32> %c, <i32 31, i32 31>
155   %ashr = ashr <2 x i32> %shl, <i32 31, i32 31>
156   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
157   ret void
158 }
159
160 ; FUNC-LABEL: @sext_in_reg_v4i1_to_v4i32
161 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
162 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
163 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
164 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
165 ; SI: BUFFER_STORE_DWORDX4
166
167 ; EG: BFE
168 ; EG: BFE
169 ; EG: BFE
170 ; EG: BFE
171 define void @sext_in_reg_v4i1_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) nounwind {
172   %c = add <4 x i32> %a, %b ; add to prevent folding into extload
173   %shl = shl <4 x i32> %c, <i32 31, i32 31, i32 31, i32 31>
174   %ashr = ashr <4 x i32> %shl, <i32 31, i32 31, i32 31, i32 31>
175   store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
176   ret void
177 }
178
179 ; FUNC-LABEL: @sext_in_reg_v2i8_to_v2i32
180 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
181 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
182 ; SI: BUFFER_STORE_DWORDX2
183
184 ; EG: BFE
185 ; EG: BFE
186 define void @sext_in_reg_v2i8_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
187   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
188   %shl = shl <2 x i32> %c, <i32 24, i32 24>
189   %ashr = ashr <2 x i32> %shl, <i32 24, i32 24>
190   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
191   ret void
192 }
193
194 ; FUNC-LABEL: @sext_in_reg_v4i8_to_v4i32
195 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
196 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
197 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
198 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
199 ; SI: BUFFER_STORE_DWORDX4
200
201 ; EG: BFE
202 ; EG: BFE
203 ; EG: BFE
204 ; EG: BFE
205 define void @sext_in_reg_v4i8_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) nounwind {
206   %c = add <4 x i32> %a, %b ; add to prevent folding into extload
207   %shl = shl <4 x i32> %c, <i32 24, i32 24, i32 24, i32 24>
208   %ashr = ashr <4 x i32> %shl, <i32 24, i32 24, i32 24, i32 24>
209   store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
210   ret void
211 }
212
213 ; FUNC-LABEL: @sext_in_reg_v2i16_to_v2i32
214 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
215 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
216 ; SI: BUFFER_STORE_DWORDX2
217
218 ; EG: BFE
219 ; EG: BFE
220 define void @sext_in_reg_v2i16_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
221   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
222   %shl = shl <2 x i32> %c, <i32 24, i32 24>
223   %ashr = ashr <2 x i32> %shl, <i32 24, i32 24>
224   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
225   ret void
226 }
227
228 ; FUNC-LABEL: @testcase
229 define void @testcase(i8 addrspace(1)* %out, i8 %a) nounwind {
230   %and_a_1 = and i8 %a, 1
231   %cmp_eq = icmp eq i8 %and_a_1, 0
232   %cmp_slt = icmp slt i8 %a, 0
233   %sel0 = select i1 %cmp_slt, i8 0, i8 %a
234   %sel1 = select i1 %cmp_eq, i8 0, i8 %a
235   %xor = xor i8 %sel0, %sel1
236   store i8 %xor, i8 addrspace(1)* %out
237   ret void
238 }
239
240 ; FUNC-LABEL: @testcase_3
241 define void @testcase_3(i8 addrspace(1)* %out, i8 %a) nounwind {
242   %and_a_1 = and i8 %a, 1
243   %cmp_eq = icmp eq i8 %and_a_1, 0
244   %cmp_slt = icmp slt i8 %a, 0
245   %sel0 = select i1 %cmp_slt, i8 0, i8 %a
246   %sel1 = select i1 %cmp_eq, i8 0, i8 %a
247   %xor = xor i8 %sel0, %sel1
248   store i8 %xor, i8 addrspace(1)* %out
249   ret void
250 }