1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i32 @test4(i32 %a) nounwind {
8 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 %a, 255
9 ; CHECK-NEXT: ret i32 [[TMP2]]
11 %tmp2 = tail call i32 @llvm.bswap.i32( i32 %a )
12 %tmp4 = lshr i32 %tmp2, 24
17 define i32 @test6(i32 %a) nounwind {
18 ; CHECK-LABEL: @test6(
19 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 %a, 24
20 ; CHECK-NEXT: ret i32 [[TMP2]]
22 %tmp2 = tail call i32 @llvm.bswap.i32( i32 %a )
23 %tmp4 = and i32 %tmp2, 255
28 define i16 @test7(i32 %A) {
29 ; CHECK-LABEL: @test7(
30 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 %A, 16
31 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[TMP1]] to i16
32 ; CHECK-NEXT: ret i16 [[D]]
34 %B = tail call i32 @llvm.bswap.i32(i32 %A) nounwind
35 %C = trunc i32 %B to i16
36 %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
40 define i16 @test8(i64 %A) {
41 ; CHECK-LABEL: @test8(
42 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 %A, 48
43 ; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i16
44 ; CHECK-NEXT: ret i16 [[D]]
46 %B = tail call i64 @llvm.bswap.i64(i64 %A) nounwind
47 %C = trunc i64 %B to i16
48 %D = tail call i16 @llvm.bswap.i16(i16 %C) nounwind
52 ; Misc: Fold bswap(undef) to undef.
55 ; CHECK-NEXT: ret i64 undef
57 %a = call i64 @llvm.bswap.i64(i64 undef)
62 ; Fold: OP( BSWAP(x), BSWAP(y) ) -> BSWAP( OP(x, y) )
63 ; Fold: OP( BSWAP(x), CONSTANT ) -> BSWAP( OP(x, BSWAP(CONSTANT) ) )
64 define i16 @bs_and16i(i16 %a, i16 %b) #0 {
65 ; CHECK-LABEL: @bs_and16i(
66 ; CHECK-NEXT: [[TMP1:%.*]] = and i16 %a, 4391
67 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.bswap.i16(i16 [[TMP1]])
68 ; CHECK-NEXT: ret i16 [[TMP2]]
70 %1 = tail call i16 @llvm.bswap.i16(i16 %a)
71 %2 = and i16 %1, 10001
75 define i16 @bs_and16(i16 %a, i16 %b) #0 {
76 ; CHECK-LABEL: @bs_and16(
77 ; CHECK-NEXT: [[TMP1:%.*]] = and i16 %a, %b
78 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.bswap.i16(i16 [[TMP1]])
79 ; CHECK-NEXT: ret i16 [[TMP2]]
81 %tmp1 = tail call i16 @llvm.bswap.i16(i16 %a)
82 %tmp2 = tail call i16 @llvm.bswap.i16(i16 %b)
83 %tmp3 = and i16 %tmp1, %tmp2
87 define i16 @bs_or16(i16 %a, i16 %b) #0 {
88 ; CHECK-LABEL: @bs_or16(
89 ; CHECK-NEXT: [[TMP1:%.*]] = or i16 %a, %b
90 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.bswap.i16(i16 [[TMP1]])
91 ; CHECK-NEXT: ret i16 [[TMP2]]
93 %tmp1 = tail call i16 @llvm.bswap.i16(i16 %a)
94 %tmp2 = tail call i16 @llvm.bswap.i16(i16 %b)
95 %tmp3 = or i16 %tmp1, %tmp2
99 define i16 @bs_xor16(i16 %a, i16 %b) #0 {
100 ; CHECK-LABEL: @bs_xor16(
101 ; CHECK-NEXT: [[TMP1:%.*]] = xor i16 %a, %b
102 ; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.bswap.i16(i16 [[TMP1]])
103 ; CHECK-NEXT: ret i16 [[TMP2]]
105 %tmp1 = tail call i16 @llvm.bswap.i16(i16 %a)
106 %tmp2 = tail call i16 @llvm.bswap.i16(i16 %b)
107 %tmp3 = xor i16 %tmp1, %tmp2
111 define i32 @bs_and32i(i32 %a, i32 %b) #0 {
112 ; CHECK-LABEL: @bs_and32i(
113 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, -1585053440
114 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.bswap.i32(i32 [[TMP1]])
115 ; CHECK-NEXT: ret i32 [[TMP2]]
117 %tmp1 = tail call i32 @llvm.bswap.i32(i32 %a)
118 %tmp2 = and i32 %tmp1, 100001
122 define i32 @bs_and32(i32 %a, i32 %b) #0 {
123 ; CHECK-LABEL: @bs_and32(
124 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, %b
125 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.bswap.i32(i32 [[TMP1]])
126 ; CHECK-NEXT: ret i32 [[TMP2]]
128 %tmp1 = tail call i32 @llvm.bswap.i32(i32 %a)
129 %tmp2 = tail call i32 @llvm.bswap.i32(i32 %b)
130 %tmp3 = and i32 %tmp1, %tmp2
134 define i32 @bs_or32(i32 %a, i32 %b) #0 {
135 ; CHECK-LABEL: @bs_or32(
136 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 %a, %b
137 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.bswap.i32(i32 [[TMP1]])
138 ; CHECK-NEXT: ret i32 [[TMP2]]
140 %tmp1 = tail call i32 @llvm.bswap.i32(i32 %a)
141 %tmp2 = tail call i32 @llvm.bswap.i32(i32 %b)
142 %tmp3 = or i32 %tmp1, %tmp2
146 define i32 @bs_xor32(i32 %a, i32 %b) #0 {
147 ; CHECK-LABEL: @bs_xor32(
148 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 %a, %b
149 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.bswap.i32(i32 [[TMP1]])
150 ; CHECK-NEXT: ret i32 [[TMP2]]
152 %tmp1 = tail call i32 @llvm.bswap.i32(i32 %a)
153 %tmp2 = tail call i32 @llvm.bswap.i32(i32 %b)
154 %tmp3 = xor i32 %tmp1, %tmp2
158 define i64 @bs_and64i(i64 %a, i64 %b) #0 {
159 ; CHECK-LABEL: @bs_and64i(
160 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 %a, 129085117527228416
161 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP1]])
162 ; CHECK-NEXT: ret i64 [[TMP2]]
164 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
165 %tmp2 = and i64 %tmp1, 1000000001
169 define i64 @bs_and64(i64 %a, i64 %b) #0 {
170 ; CHECK-LABEL: @bs_and64(
171 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 %a, %b
172 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP1]])
173 ; CHECK-NEXT: ret i64 [[TMP2]]
175 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
176 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
177 %tmp3 = and i64 %tmp1, %tmp2
181 define i64 @bs_or64(i64 %a, i64 %b) #0 {
182 ; CHECK-LABEL: @bs_or64(
183 ; CHECK-NEXT: [[TMP1:%.*]] = or i64 %a, %b
184 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP1]])
185 ; CHECK-NEXT: ret i64 [[TMP2]]
187 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
188 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
189 %tmp3 = or i64 %tmp1, %tmp2
193 define i64 @bs_xor64(i64 %a, i64 %b) #0 {
194 ; CHECK-LABEL: @bs_xor64(
195 ; CHECK-NEXT: [[TMP1:%.*]] = xor i64 %a, %b
196 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP1]])
197 ; CHECK-NEXT: ret i64 [[TMP2]]
199 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
200 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
201 %tmp3 = xor i64 %tmp1, %tmp2
205 define <2 x i32> @bs_and32vec(<2 x i32> %a, <2 x i32> %b) #0 {
206 ; CHECK-LABEL: @bs_and32vec(
207 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], [[B:%.*]]
208 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
209 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
211 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
212 %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)
213 %tmp3 = and <2 x i32> %tmp1, %tmp2
217 define <2 x i32> @bs_or32vec(<2 x i32> %a, <2 x i32> %b) #0 {
218 ; CHECK-LABEL: @bs_or32vec(
219 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
220 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
221 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
223 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
224 %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)
225 %tmp3 = or <2 x i32> %tmp1, %tmp2
229 define <2 x i32> @bs_xor32vec(<2 x i32> %a, <2 x i32> %b) #0 {
230 ; CHECK-LABEL: @bs_xor32vec(
231 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[A:%.*]], [[B:%.*]]
232 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
233 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
235 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
236 %tmp2 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %b)
237 %tmp3 = xor <2 x i32> %tmp1, %tmp2
241 define <2 x i32> @bs_and32ivec(<2 x i32> %a, <2 x i32> %b) #0 {
242 ; CHECK-LABEL: @bs_and32ivec(
243 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[A:%.*]], <i32 -1585053440, i32 -1585053440>
244 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
245 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
247 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
248 %tmp2 = and <2 x i32> %tmp1, <i32 100001, i32 100001>
252 define <2 x i32> @bs_or32ivec(<2 x i32> %a, <2 x i32> %b) #0 {
253 ; CHECK-LABEL: @bs_or32ivec(
254 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[A:%.*]], <i32 -1585053440, i32 -1585053440>
255 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
256 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
258 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
259 %tmp2 = or <2 x i32> %tmp1, <i32 100001, i32 100001>
263 define <2 x i32> @bs_xor32ivec(<2 x i32> %a, <2 x i32> %b) #0 {
264 ; CHECK-LABEL: @bs_xor32ivec(
265 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[A:%.*]], <i32 -1585053440, i32 -1585053440>
266 ; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.bswap.v2i32(<2 x i32> [[TMP1]])
267 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
269 %tmp1 = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %a)
270 %tmp2 = xor <2 x i32> %tmp1, <i32 100001, i32 100001>
274 define i64 @bs_and64_multiuse1(i64 %a, i64 %b) #0 {
275 ; CHECK-LABEL: @bs_and64_multiuse1(
276 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.bswap.i64(i64 [[A:%.*]])
277 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i64 @llvm.bswap.i64(i64 [[B:%.*]])
278 ; CHECK-NEXT: [[TMP3:%.*]] = and i64 [[TMP1]], [[TMP2]]
279 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], [[TMP1]]
280 ; CHECK-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], [[TMP2]]
281 ; CHECK-NEXT: ret i64 [[TMP5]]
283 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
284 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
285 %tmp3 = and i64 %tmp1, %tmp2
286 %tmp4 = mul i64 %tmp3, %tmp1 ; to increase use count of the bswaps
287 %tmp5 = mul i64 %tmp4, %tmp2 ; to increase use count of the bswaps
291 define i64 @bs_and64_multiuse2(i64 %a, i64 %b) #0 {
292 ; CHECK-LABEL: @bs_and64_multiuse2(
293 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.bswap.i64(i64 [[A:%.*]])
294 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[A]], [[B:%.*]]
295 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP2]])
296 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], [[TMP1]]
297 ; CHECK-NEXT: ret i64 [[TMP4]]
299 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
300 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
301 %tmp3 = and i64 %tmp1, %tmp2
302 %tmp4 = mul i64 %tmp3, %tmp1 ; to increase use count of the bswaps
306 define i64 @bs_and64_multiuse3(i64 %a, i64 %b) #0 {
307 ; CHECK-LABEL: @bs_and64_multiuse3(
308 ; CHECK-NEXT: [[TMP2:%.*]] = tail call i64 @llvm.bswap.i64(i64 [[B:%.*]])
309 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[A:%.*]], [[B]]
310 ; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.bswap.i64(i64 [[TMP1]])
311 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], [[TMP2]]
312 ; CHECK-NEXT: ret i64 [[TMP4]]
314 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
315 %tmp2 = tail call i64 @llvm.bswap.i64(i64 %b)
316 %tmp3 = and i64 %tmp1, %tmp2
317 %tmp4 = mul i64 %tmp3, %tmp2 ; to increase use count of the bswaps
321 define i64 @bs_and64i_multiuse(i64 %a, i64 %b) #0 {
322 ; CHECK-LABEL: @bs_and64i_multiuse(
323 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i64 @llvm.bswap.i64(i64 [[A:%.*]])
324 ; CHECK-NEXT: [[TMP2:%.*]] = and i64 [[TMP1]], 1000000001
325 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], [[TMP1]]
326 ; CHECK-NEXT: ret i64 [[TMP3]]
328 %tmp1 = tail call i64 @llvm.bswap.i64(i64 %a)
329 %tmp2 = and i64 %tmp1, 1000000001
330 %tmp3 = mul i64 %tmp2, %tmp1 ; to increase use count of the bswap
334 declare i16 @llvm.bswap.i16(i16)
335 declare i32 @llvm.bswap.i32(i32)
336 declare i64 @llvm.bswap.i64(i64)
337 declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>)