1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
6 define i32 @test1(i32 %x) {
8 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 31
9 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[AND]], 63
10 ; CHECK-NEXT: ret i32 [[SUB]]
13 %sub = sub i32 63, %and
17 define <2 x i32> @test1vec(<2 x i32> %x) {
18 ; CHECK-LABEL: @test1vec(
19 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]], <i32 31, i32 31>
20 ; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[AND]], <i32 63, i32 63>
21 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
23 %and = and <2 x i32> %x, <i32 31, i32 31>
24 %sub = sub <2 x i32> <i32 63, i32 63>, %and
28 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
30 define i32 @test2(i32 %x) nounwind {
31 ; CHECK-LABEL: @test2(
32 ; CHECK-NEXT: [[COUNT:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 true) [[ATTR2:#.*]], [[RNG0:!range !.*]]
33 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[COUNT]], 31
34 ; CHECK-NEXT: ret i32 [[SUB]]
36 %count = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) nounwind readnone
37 %sub = sub i32 31, %count
41 define i32 @xor_add(i32 %x) {
42 ; CHECK-LABEL: @xor_add(
43 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 31
44 ; CHECK-NEXT: [[ADD:%.*]] = sub nuw nsw i32 73, [[AND]]
45 ; CHECK-NEXT: ret i32 [[ADD]]
48 %xor = xor i32 %and, 31
49 %add = add i32 %xor, 42
53 define i32 @xor_add_extra_use(i32 %x) {
54 ; CHECK-LABEL: @xor_add_extra_use(
55 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 31
56 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND]], 31
57 ; CHECK-NEXT: call void @use(i32 [[XOR]])
58 ; CHECK-NEXT: [[ADD:%.*]] = sub nuw nsw i32 73, [[AND]]
59 ; CHECK-NEXT: ret i32 [[ADD]]
62 %xor = xor i32 %and, 31
63 call void @use(i32 %xor)
64 %add = add i32 %xor, 42
68 define <2 x i8> @xor_add_splat(<2 x i8> %x) {
69 ; CHECK-LABEL: @xor_add_splat(
70 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 24, i8 24>
71 ; CHECK-NEXT: [[ADD:%.*]] = sub nuw nsw <2 x i8> <i8 105, i8 105>, [[AND]]
72 ; CHECK-NEXT: ret <2 x i8> [[ADD]]
74 %and = and <2 x i8> %x, <i8 24, i8 24>
75 %xor = xor <2 x i8> %and, <i8 63, i8 63>
76 %add = add <2 x i8> %xor, <i8 42, i8 42>
80 define <2 x i8> @xor_add_splat_undef(<2 x i8> %x) {
81 ; CHECK-LABEL: @xor_add_splat_undef(
82 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 24, i8 24>
83 ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[AND]], <i8 63, i8 undef>
84 ; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[XOR]], <i8 42, i8 42>
85 ; CHECK-NEXT: ret <2 x i8> [[ADD]]
87 %and = and <2 x i8> %x, <i8 24, i8 24>
88 %xor = xor <2 x i8> %and, <i8 63, i8 undef>
89 %add = add <2 x i8> %xor, <i8 42, i8 42>