1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @a_true_implies_b_true(i8 %z, i1 %X, i1 %Y) {
5 ; CHECK-LABEL: @a_true_implies_b_true(
6 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
7 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[X:%.*]], i1 false
8 ; CHECK-NEXT: ret i1 [[RES]]
10 %a = icmp ugt i8 %z, 20
11 %b = icmp ugt i8 %z, 10
12 %sel = select i1 %b, i1 %X, i1 %Y
13 %res = select i1 %a, i1 %sel, i1 false
17 define <2 x i1> @a_true_implies_b_true_vec(i8 %z0, <2 x i1> %X, <2 x i1> %Y) {
18 ; CHECK-LABEL: @a_true_implies_b_true_vec(
19 ; CHECK-NEXT: [[A0:%.*]] = insertelement <2 x i8> poison, i8 [[Z0:%.*]], i64 0
20 ; CHECK-NEXT: [[Z:%.*]] = shufflevector <2 x i8> [[A0]], <2 x i8> poison, <2 x i32> zeroinitializer
21 ; CHECK-NEXT: [[A:%.*]] = icmp ugt <2 x i8> [[Z]], <i8 20, i8 19>
22 ; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[Z0]], 10
23 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[B]], <2 x i1> [[X:%.*]], <2 x i1> [[Y:%.*]]
24 ; CHECK-NEXT: [[RES:%.*]] = select <2 x i1> [[A]], <2 x i1> [[SEL]], <2 x i1> zeroinitializer
25 ; CHECK-NEXT: ret <2 x i1> [[RES]]
28 %a0 = insertelement <2 x i8> poison, i8 %z0, i8 0
29 %z = shufflevector <2 x i8> %a0, <2 x i8> poison, <2 x i32> zeroinitializer
30 %a = icmp ugt <2 x i8> %z, <i8 20, i8 19>
31 %b = icmp ugt i8 %z0, 10
32 %sel = select i1 %b, <2 x i1> %X, <2 x i1> %Y
33 %res = select <2 x i1> %a, <2 x i1> %sel, <2 x i1> zeroinitializer
37 define i1 @a_true_implies_b_true2(i8 %z, i1 %X, i1 %Y) {
38 ; CHECK-LABEL: @a_true_implies_b_true2(
39 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
40 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[X:%.*]], i1 false
41 ; CHECK-NEXT: ret i1 [[RES]]
43 %a = icmp ugt i8 %z, 20
44 %b = icmp ugt i8 %z, 10
45 %sel = select i1 %b, i1 %X, i1 %Y
46 %res = and i1 %a, %sel
50 define i1 @a_true_implies_b_true2_comm(i8 %z, i1 %X, i1 %Y) {
51 ; CHECK-LABEL: @a_true_implies_b_true2_comm(
52 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
53 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[X:%.*]], i1 false
54 ; CHECK-NEXT: ret i1 [[RES]]
56 %a = icmp ugt i8 %z, 20
57 %b = icmp ugt i8 %z, 10
58 %sel = select i1 %b, i1 %X, i1 %Y
59 %res = and i1 %sel, %a
63 define i1 @a_true_implies_b_false(i8 %z, i1 %X, i1 %Y) {
64 ; CHECK-LABEL: @a_true_implies_b_false(
65 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
66 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[Y:%.*]], i1 false
67 ; CHECK-NEXT: ret i1 [[RES]]
69 %a = icmp ugt i8 %z, 20
70 %b = icmp ult i8 %z, 10
71 %sel = select i1 %b, i1 %X, i1 %Y
72 %res = select i1 %a, i1 %sel, i1 false
76 define i1 @a_true_implies_b_false2(i8 %z, i1 %X, i1 %Y) {
77 ; CHECK-LABEL: @a_true_implies_b_false2(
78 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
79 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[Y:%.*]], i1 false
80 ; CHECK-NEXT: ret i1 [[RES]]
82 %a = icmp ugt i8 %z, 20
83 %b = icmp eq i8 %z, 10
84 %sel = select i1 %b, i1 %X, i1 %Y
85 %res = and i1 %a, %sel
89 define i1 @a_true_implies_b_false2_comm(i8 %z, i1 %X, i1 %Y) {
90 ; CHECK-LABEL: @a_true_implies_b_false2_comm(
91 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 20
92 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[Y:%.*]], i1 false
93 ; CHECK-NEXT: ret i1 [[RES]]
95 %a = icmp ugt i8 %z, 20
96 %b = icmp eq i8 %z, 10
97 %sel = select i1 %b, i1 %X, i1 %Y
98 %res = and i1 %sel, %a
102 define i1 @a_false_implies_b_true(i8 %z, i1 %X, i1 %Y) {
103 ; CHECK-LABEL: @a_false_implies_b_true(
104 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
105 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[X:%.*]]
106 ; CHECK-NEXT: ret i1 [[RES]]
108 %a = icmp ugt i8 %z, 10
109 %b = icmp ult i8 %z, 20
110 %sel = select i1 %b, i1 %X, i1 %Y
111 %res = select i1 %a, i1 true, i1 %sel
115 define i1 @a_false_implies_b_true2(i8 %z, i1 %X, i1 %Y) {
116 ; CHECK-LABEL: @a_false_implies_b_true2(
117 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
118 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[X:%.*]]
119 ; CHECK-NEXT: ret i1 [[RES]]
121 %a = icmp ugt i8 %z, 10
122 %b = icmp ult i8 %z, 20
123 %sel = select i1 %b, i1 %X, i1 %Y
124 %res = or i1 %a, %sel
128 define i1 @a_false_implies_b_true2_comm(i8 %z, i1 %X, i1 %Y) {
129 ; CHECK-LABEL: @a_false_implies_b_true2_comm(
130 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
131 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[X:%.*]]
132 ; CHECK-NEXT: ret i1 [[RES]]
134 %a = icmp ugt i8 %z, 10
135 %b = icmp ult i8 %z, 20
136 %sel = select i1 %b, i1 %X, i1 %Y
137 %res = or i1 %sel, %a
141 define i1 @a_false_implies_b_false(i8 %z, i1 %X, i1 %Y) {
142 ; CHECK-LABEL: @a_false_implies_b_false(
143 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
144 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[Y:%.*]]
145 ; CHECK-NEXT: ret i1 [[RES]]
147 %a = icmp ugt i8 %z, 10
148 %b = icmp ugt i8 %z, 20
149 %sel = select i1 %b, i1 %X, i1 %Y
150 %res = select i1 %a, i1 true, i1 %sel
154 define i1 @a_false_implies_b_false2(i8 %z, i1 %X, i1 %Y) {
155 ; CHECK-LABEL: @a_false_implies_b_false2(
156 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
157 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[Y:%.*]]
158 ; CHECK-NEXT: ret i1 [[RES]]
160 %a = icmp ugt i8 %z, 10
161 %b = icmp ugt i8 %z, 20
162 %sel = select i1 %b, i1 %X, i1 %Y
163 %res = or i1 %a, %sel
167 define i1 @a_false_implies_b_false2_comm(i8 %z, i1 %X, i1 %Y) {
168 ; CHECK-LABEL: @a_false_implies_b_false2_comm(
169 ; CHECK-NEXT: [[A:%.*]] = icmp ugt i8 [[Z:%.*]], 10
170 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[Y:%.*]]
171 ; CHECK-NEXT: ret i1 [[RES]]
173 %a = icmp ugt i8 %z, 10
174 %b = icmp ugt i8 %z, 20
175 %sel = select i1 %b, i1 %X, i1 %Y
176 %res = or i1 %sel, %a