1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
6 define i32 @sub_to_and(i32 %x, i32 %y) {
7 ; CHECK-LABEL: @sub_to_and(
8 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
10 ; CHECK-NEXT: ret i32 [[SUB]]
14 %sub = sub i32 %xor, %or
18 define i32 @sub_to_and_extra_use_sub(i32 %x, i32 %y) {
19 ; CHECK-LABEL: @sub_to_and_extra_use_sub(
20 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
21 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
22 ; CHECK-NEXT: call void @use(i32 [[SUB]])
23 ; CHECK-NEXT: ret i32 [[SUB]]
27 %sub = sub i32 %xor, %or
28 call void @use(i32 %sub)
32 define i32 @sub_to_and_extra_use_and(i32 %x, i32 %y) {
33 ; CHECK-LABEL: @sub_to_and_extra_use_and(
34 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
35 ; CHECK-NEXT: call void @use(i32 [[XOR]])
36 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X]], [[Y]]
37 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
38 ; CHECK-NEXT: ret i32 [[SUB]]
42 call void @use(i32 %xor)
43 %sub = sub i32 %xor, %or
47 define i32 @sub_to_and_extra_use_or(i32 %x, i32 %y) {
48 ; CHECK-LABEL: @sub_to_and_extra_use_or(
49 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
50 ; CHECK-NEXT: call void @use(i32 [[OR]])
51 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X]], [[Y]]
52 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
53 ; CHECK-NEXT: ret i32 [[SUB]]
56 call void @use(i32 %or)
58 %sub = sub i32 %xor, %or
62 define i32 @sub_to_and_or_commuted(i32 %x, i32 %y) {
63 ; CHECK-LABEL: @sub_to_and_or_commuted(
64 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
65 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
66 ; CHECK-NEXT: ret i32 [[SUB]]
70 %sub = sub i32 %xor, %or
74 define i32 @sub_to_and_and_commuted(i32 %x, i32 %y) {
75 ; CHECK-LABEL: @sub_to_and_and_commuted(
76 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[Y:%.*]], [[X:%.*]]
77 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[TMP1]]
78 ; CHECK-NEXT: ret i32 [[SUB]]
82 %sub = sub i32 %xor, %or
86 define <2 x i32> @sub_to_and_vec(<2 x i32> %x, <2 x i32> %y) {
87 ; CHECK-LABEL: @sub_to_and_vec(
88 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[Y:%.*]], [[X:%.*]]
89 ; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i32> zeroinitializer, [[TMP1]]
90 ; CHECK-NEXT: ret <2 x i32> [[SUB]]
92 %or = or <2 x i32> %x, %y
93 %xor = xor <2 x i32> %y, %x
94 %sub = sub <2 x i32> %xor, %or
100 define i32 @sub_to_and_extra_use_and_or(i32 %x, i32 %y) {
101 ; CHECK-LABEL: @sub_to_and_extra_use_and_or(
102 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
103 ; CHECK-NEXT: call void @use(i32 [[OR]])
104 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
105 ; CHECK-NEXT: call void @use(i32 [[XOR]])
106 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[XOR]], [[OR]]
107 ; CHECK-NEXT: ret i32 [[SUB]]
110 call void @use(i32 %or)
111 %xor = xor i32 %x, %y
112 call void @use(i32 %xor)
113 %sub = sub i32 %xor, %or