1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 define i32 @test1(i32 %x) {
6 ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 31
7 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[AND]], 63
8 ; CHECK-NEXT: ret i32 [[SUB]]
11 %sub = sub i32 63, %and
15 define <2 x i32> @test1vec(<2 x i32> %x) {
16 ; CHECK-LABEL: @test1vec(
17 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> %x, <i32 31, i32 31>
18 ; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[AND]], <i32 63, i32 63>
19 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
21 %and = and <2 x i32> %x, <i32 31, i32 31>
22 %sub = sub <2 x i32> <i32 63, i32 63>, %and
26 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
28 define i32 @test2(i32 %x) nounwind {
29 ; CHECK-LABEL: @test2(
30 ; CHECK-NEXT: [[COUNT:%.*]] = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true)
31 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[COUNT]], 31
32 ; CHECK-NEXT: ret i32 [[SUB]]
34 %count = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) nounwind readnone
35 %sub = sub i32 31, %count
39 define i32 @test3(i32 %x) {
40 ; CHECK-LABEL: @test3(
41 ; CHECK-NEXT: [[AND:%.*]] = and i32 %x, 31
42 ; CHECK-NEXT: [[ADD:%.*]] = sub nuw nsw i32 73, [[AND]]
43 ; CHECK-NEXT: ret i32 [[ADD]]
46 %sub = xor i32 31, %and
47 %add = add i32 %sub, 42