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
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]],
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
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]],
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
26 %ashr = ashr i32 %shl, 24
27 store i32 %ashr, i32 addrspace(1)* %out, align 4
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]],
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
40 %ashr = ashr i32 %shl, 16
41 store i32 %ashr, i32 addrspace(1)* %out, align 4
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]],
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
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
66 define void @sext_in_reg_i8_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
69 %ashr = ashr i64 %shl, 56
70 store i64 %ashr, i64 addrspace(1)* %out, align 8
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
81 define void @sext_in_reg_i16_to_i64(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
84 %ashr = ashr i64 %shl, 48
85 store i64 %ashr, i64 addrspace(1)* %out, align 8
89 ; FUNC-LABEL: @sext_in_reg_i32_to_i64
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 {
98 %ashr = ashr i64 %shl, 32
99 store i64 %ashr, i64 addrspace(1)* %out, align 8
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
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
118 ; FUNC-LABEL: @sext_in_reg_i1_in_i32_other_amount
120 ; SI: S_LSHL_B32 [[REG:s[0-9]+]], {{s[0-9]+}}, 6
121 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG]], 7
123 define void @sext_in_reg_i1_in_i32_other_amount(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
127 store i32 %y, i32 addrspace(1)* %out
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
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
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
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
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
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
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
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
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
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
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
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
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
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