1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
6 define i32 @sub_to_xor(i32 %x, i32 %y) {
7 ; CHECK-LABEL: @sub_to_xor(
8 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: ret i32 [[SUB]]
13 %sub = sub i32 %or, %and
17 define i32 @sub_to_xor_extra_use_sub(i32 %x, i32 %y) {
18 ; CHECK-LABEL: @sub_to_xor_extra_use_sub(
19 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
20 ; CHECK-NEXT: call void @use(i32 [[SUB]])
21 ; CHECK-NEXT: ret i32 [[SUB]]
25 %sub = sub i32 %or, %and
26 call void @use(i32 %sub)
30 define i32 @sub_to_xor_extra_use_and(i32 %x, i32 %y) {
31 ; CHECK-LABEL: @sub_to_xor_extra_use_and(
32 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
33 ; CHECK-NEXT: call void @use(i32 [[AND]])
34 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X]], [[Y]]
35 ; CHECK-NEXT: ret i32 [[SUB]]
39 call void @use(i32 %and)
40 %sub = sub i32 %or, %and
44 define i32 @sub_to_xor_extra_use_or(i32 %x, i32 %y) {
45 ; CHECK-LABEL: @sub_to_xor_extra_use_or(
46 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
47 ; CHECK-NEXT: call void @use(i32 [[OR]])
48 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X]], [[Y]]
49 ; CHECK-NEXT: ret i32 [[SUB]]
52 call void @use(i32 %or)
54 %sub = sub i32 %or, %and
58 define i32 @sub_to_xor_or_commuted(i32 %x, i32 %y) {
59 ; CHECK-LABEL: @sub_to_xor_or_commuted(
60 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
61 ; CHECK-NEXT: ret i32 [[SUB]]
65 %sub = sub i32 %or, %and
69 define i32 @sub_to_xor_and_commuted(i32 %x, i32 %y) {
70 ; CHECK-LABEL: @sub_to_xor_and_commuted(
71 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]
72 ; CHECK-NEXT: ret i32 [[SUB]]
76 %sub = sub i32 %or, %and
80 define <2 x i32> @sub_to_xor_vec(<2 x i32> %x, <2 x i32> %y) {
81 ; CHECK-LABEL: @sub_to_xor_vec(
82 ; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[Y:%.*]], [[X:%.*]]
83 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
85 %or = or <2 x i32> %x, %y
86 %and = and <2 x i32> %y, %x
87 %sub = sub <2 x i32> %or, %and
93 define i32 @sub_to_xor_wrong_arg(i32 %x, i32 %y, i32 %z) {
94 ; CHECK-LABEL: @sub_to_xor_wrong_arg(
95 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
96 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[Z:%.*]]
97 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[AND]], [[OR]]
98 ; CHECK-NEXT: ret i32 [[SUB]]
101 %and = and i32 %x, %z
102 %sub = sub i32 %and, %or