R600: Match sign_extend_inreg to BFE instructions
[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 ; This is broken on Evergreen for some reason related to the <1 x i64> kernel arguments.
90 ; XFUNC-LABEL: @sext_in_reg_i8_to_v1i64
91 ; XSI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
92 ; XSI: V_ASHRREV_I32_e32 {{v[0-9]+}}, 31,
93 ; XSI: BUFFER_STORE_DWORD
94 ; XEG: BFE_INT
95 ; XEG: ASHR
96 ; define void @sext_in_reg_i8_to_v1i64(<1 x i64> addrspace(1)* %out, <1 x i64> %a, <1 x i64> %b) nounwind {
97 ;   %c = add <1 x i64> %a, %b
98 ;   %shl = shl <1 x i64> %c, <i64 56>
99 ;   %ashr = ashr <1 x i64> %shl, <i64 56>
100 ;   store <1 x i64> %ashr, <1 x i64> addrspace(1)* %out, align 8
101 ;   ret void
102 ; }
103
104 ; FUNC-LABEL: @sext_in_reg_i1_in_i32_other_amount
105 ; SI-NOT: BFE
106 ; SI: S_LSHL_B32 [[REG:s[0-9]+]], {{s[0-9]+}}, 6
107 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG]], 7
108 ; EG-NOT: BFE
109 define void @sext_in_reg_i1_in_i32_other_amount(i32 addrspace(1)* %out, i32 %a, i32 %b) nounwind {
110   %c = add i32 %a, %b
111   %x = shl i32 %c, 6
112   %y = ashr i32 %x, 7
113   store i32 %y, i32 addrspace(1)* %out
114   ret void
115 }
116
117 ; FUNC-LABEL: @sext_in_reg_v2i1_in_v2i32_other_amount
118 ; SI: S_LSHL_B32 [[REG0:s[0-9]+]], {{s[0-9]}}, 6
119 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG0]], 7
120 ; SI: S_LSHL_B32 [[REG1:s[0-9]+]], {{s[0-9]}}, 6
121 ; SI: S_ASHR_I32 {{s[0-9]+}}, [[REG1]], 7
122 ; EG-NOT: BFE
123 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 {
124   %c = add <2 x i32> %a, %b
125   %x = shl <2 x i32> %c, <i32 6, i32 6>
126   %y = ashr <2 x i32> %x, <i32 7, i32 7>
127   store <2 x i32> %y, <2 x i32> addrspace(1)* %out, align 2
128   ret void
129 }
130
131
132 ; FUNC-LABEL: @sext_in_reg_v2i1_to_v2i32
133 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
134 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
135 ; SI: BUFFER_STORE_DWORDX2
136 ; EG: BFE
137 ; EG: BFE
138 define void @sext_in_reg_v2i1_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
139   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
140   %shl = shl <2 x i32> %c, <i32 31, i32 31>
141   %ashr = ashr <2 x i32> %shl, <i32 31, i32 31>
142   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
143   ret void
144 }
145
146 ; FUNC-LABEL: @sext_in_reg_v4i1_to_v4i32
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: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
150 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 1
151 ; SI: BUFFER_STORE_DWORDX4
152
153 ; EG: BFE
154 ; EG: BFE
155 ; EG: BFE
156 ; EG: BFE
157 define void @sext_in_reg_v4i1_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) nounwind {
158   %c = add <4 x i32> %a, %b ; add to prevent folding into extload
159   %shl = shl <4 x i32> %c, <i32 31, i32 31, i32 31, i32 31>
160   %ashr = ashr <4 x i32> %shl, <i32 31, i32 31, i32 31, i32 31>
161   store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
162   ret void
163 }
164
165 ; FUNC-LABEL: @sext_in_reg_v2i8_to_v2i32
166 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
167 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
168 ; SI: BUFFER_STORE_DWORDX2
169
170 ; EG: BFE
171 ; EG: BFE
172 define void @sext_in_reg_v2i8_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
173   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
174   %shl = shl <2 x i32> %c, <i32 24, i32 24>
175   %ashr = ashr <2 x i32> %shl, <i32 24, i32 24>
176   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
177   ret void
178 }
179
180 ; FUNC-LABEL: @sext_in_reg_v4i8_to_v4i32
181 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
182 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
183 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
184 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
185 ; SI: BUFFER_STORE_DWORDX4
186
187 ; EG: BFE
188 ; EG: BFE
189 ; EG: BFE
190 ; EG: BFE
191 define void @sext_in_reg_v4i8_to_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> %a, <4 x i32> %b) nounwind {
192   %c = add <4 x i32> %a, %b ; add to prevent folding into extload
193   %shl = shl <4 x i32> %c, <i32 24, i32 24, i32 24, i32 24>
194   %ashr = ashr <4 x i32> %shl, <i32 24, i32 24, i32 24, i32 24>
195   store <4 x i32> %ashr, <4 x i32> addrspace(1)* %out, align 8
196   ret void
197 }
198
199 ; FUNC-LABEL: @sext_in_reg_v2i16_to_v2i32
200 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
201 ; SI: V_BFE_I32 {{v[0-9]+}}, {{s[0-9]+}}, 0, 8
202 ; SI: BUFFER_STORE_DWORDX2
203
204 ; EG: BFE
205 ; EG: BFE
206 define void @sext_in_reg_v2i16_to_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) nounwind {
207   %c = add <2 x i32> %a, %b ; add to prevent folding into extload
208   %shl = shl <2 x i32> %c, <i32 24, i32 24>
209   %ashr = ashr <2 x i32> %shl, <i32 24, i32 24>
210   store <2 x i32> %ashr, <2 x i32> addrspace(1)* %out, align 8
211   ret void
212 }
213
214 ; FUNC-LABEL: @testcase
215 define void @testcase(i8 addrspace(1)* %out, i8 %a) nounwind {
216   %and_a_1 = and i8 %a, 1
217   %cmp_eq = icmp eq i8 %and_a_1, 0
218   %cmp_slt = icmp slt i8 %a, 0
219   %sel0 = select i1 %cmp_slt, i8 0, i8 %a
220   %sel1 = select i1 %cmp_eq, i8 0, i8 %a
221   %xor = xor i8 %sel0, %sel1
222   store i8 %xor, i8 addrspace(1)* %out
223   ret void
224 }
225
226 ; FUNC-LABEL: @testcase_3
227 define void @testcase_3(i8 addrspace(1)* %out, i8 %a) nounwind {
228   %and_a_1 = and i8 %a, 1
229   %cmp_eq = icmp eq i8 %and_a_1, 0
230   %cmp_slt = icmp slt i8 %a, 0
231   %sel0 = select i1 %cmp_slt, i8 0, i8 %a
232   %sel1 = select i1 %cmp_eq, i8 0, i8 %a
233   %xor = xor i8 %sel0, %sel1
234   store i8 %xor, i8 addrspace(1)* %out
235   ret void
236 }