[InstCombine] Signed saturation patterns
[llvm-core.git] / test / Transforms / InstCombine / sub-or-and-xor.ll
blob59d3c6f6b5c40d36ed1ec830a98ac4fa60454869
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 declare void @use(i32)
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]]
11   %or = or i32 %x, %y
12   %and = and i32 %x, %y
13   %sub = sub i32 %or, %and
14   ret i32 %sub
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]]
23   %or = or i32 %x, %y
24   %and = and i32 %x, %y
25   %sub = sub i32 %or, %and
26   call void @use(i32 %sub)
27   ret 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]]
37   %or = or i32 %x, %y
38   %and = and i32 %x, %y
39   call void @use(i32 %and)
40   %sub = sub i32 %or, %and
41   ret i32 %sub
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]]
51   %or = or i32 %x, %y
52   call void @use(i32 %or)
53   %and = and i32 %x, %y
54   %sub = sub i32 %or, %and
55   ret i32 %sub
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]]
63   %or = or i32 %y, %x
64   %and = and i32 %x, %y
65   %sub = sub i32 %or, %and
66   ret i32 %sub
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]]
74   %or = or i32 %x, %y
75   %and = and i32 %y, %x
76   %sub = sub i32 %or, %and
77   ret i32 %sub
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
88   ret <2 x i32> %sub
91 ; Negative tests
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]]
100   %or = or i32 %x, %y
101   %and = and i32 %x, %z
102   %sub = sub i32 %and, %or
103   ret i32 %sub