1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
6 define i1 @test1(i32 %a, i32 %b) {
8 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
9 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
10 ; CHECK-NEXT: ret i1 [[TMP2]]
12 %1 = icmp slt i32 %a, 0
13 %2 = icmp slt i32 %b, 0
14 %or.cond = or i1 %1, %2
18 define i1 @test1_logical(i32 %a, i32 %b) {
19 ; CHECK-LABEL: @test1_logical(
20 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A:%.*]], 0
21 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[B:%.*]], 0
22 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[TMP1]], i1 true, i1 [[TMP2]]
23 ; CHECK-NEXT: ret i1 [[OR_COND]]
25 %1 = icmp slt i32 %a, 0
26 %2 = icmp slt i32 %b, 0
27 %or.cond = select i1 %1, i1 true, i1 %2
31 define i1 @test2(i32 %a, i32 %b) {
32 ; CHECK-LABEL: @test2(
33 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
34 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], -1
35 ; CHECK-NEXT: ret i1 [[TMP2]]
37 %1 = icmp sgt i32 %a, -1
38 %2 = icmp sgt i32 %b, -1
39 %or.cond = or i1 %1, %2
43 define i1 @test2_logical(i32 %a, i32 %b) {
44 ; CHECK-LABEL: @test2_logical(
45 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -1
46 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[B:%.*]], -1
47 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[TMP1]], i1 true, i1 [[TMP2]]
48 ; CHECK-NEXT: ret i1 [[OR_COND]]
50 %1 = icmp sgt i32 %a, -1
51 %2 = icmp sgt i32 %b, -1
52 %or.cond = select i1 %1, i1 true, i1 %2
56 define i1 @test3(i32 %a, i32 %b) {
57 ; CHECK-LABEL: @test3(
58 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
59 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], 0
60 ; CHECK-NEXT: ret i1 [[TMP2]]
62 %1 = icmp slt i32 %a, 0
63 %2 = icmp slt i32 %b, 0
64 %or.cond = and i1 %1, %2
68 define i1 @test3_logical(i32 %a, i32 %b) {
69 ; CHECK-LABEL: @test3_logical(
70 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A:%.*]], 0
71 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[B:%.*]], 0
72 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[TMP1]], i1 [[TMP2]], i1 false
73 ; CHECK-NEXT: ret i1 [[OR_COND]]
75 %1 = icmp slt i32 %a, 0
76 %2 = icmp slt i32 %b, 0
77 %or.cond = select i1 %1, i1 %2, i1 false
81 define i1 @test4(i32 %a, i32 %b) {
82 ; CHECK-LABEL: @test4(
83 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
84 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], -1
85 ; CHECK-NEXT: ret i1 [[TMP2]]
87 %1 = icmp sgt i32 %a, -1
88 %2 = icmp sgt i32 %b, -1
89 %or.cond = and i1 %1, %2
93 define i1 @test4_logical(i32 %a, i32 %b) {
94 ; CHECK-LABEL: @test4_logical(
95 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], -1
96 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[B:%.*]], -1
97 ; CHECK-NEXT: [[OR_COND:%.*]] = select i1 [[TMP1]], i1 [[TMP2]], i1 false
98 ; CHECK-NEXT: ret i1 [[OR_COND]]
100 %1 = icmp sgt i32 %a, -1
101 %2 = icmp sgt i32 %b, -1
102 %or.cond = select i1 %1, i1 %2, i1 false
106 define void @test5(i32 %a) {
107 ; CHECK-LABEL: @test5(
108 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
109 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
110 ; CHECK-NEXT: br i1 [[TMP2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
112 ; CHECK-NEXT: tail call void @foo() #[[ATTR0:[0-9]+]]
113 ; CHECK-NEXT: ret void
115 ; CHECK-NEXT: ret void
117 %and = and i32 %a, 134217728
118 %1 = icmp eq i32 %and, 0
119 %2 = icmp sgt i32 %a, -1
120 %or.cond = and i1 %1, %2
121 br i1 %or.cond, label %if.then, label %if.end
125 tail call void @foo() nounwind
132 define void @test5_logical(i32 %a) {
133 ; CHECK-LABEL: @test5_logical(
134 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
135 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
136 ; CHECK-NEXT: br i1 [[TMP2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
138 ; CHECK-NEXT: tail call void @foo() #[[ATTR0]]
139 ; CHECK-NEXT: ret void
141 ; CHECK-NEXT: ret void
143 %and = and i32 %a, 134217728
144 %1 = icmp eq i32 %and, 0
145 %2 = icmp sgt i32 %a, -1
146 %or.cond = select i1 %1, i1 %2, i1 false
147 br i1 %or.cond, label %if.then, label %if.end
151 tail call void @foo() nounwind
158 define void @test6(i32 %a) {
159 ; CHECK-LABEL: @test6(
160 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
161 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
162 ; CHECK-NEXT: br i1 [[TMP2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
164 ; CHECK-NEXT: tail call void @foo() #[[ATTR0]]
165 ; CHECK-NEXT: ret void
167 ; CHECK-NEXT: ret void
169 %1 = icmp sgt i32 %a, -1
170 %and = and i32 %a, 134217728
171 %2 = icmp eq i32 %and, 0
172 %or.cond = and i1 %1, %2
173 br i1 %or.cond, label %if.then, label %if.end
177 tail call void @foo() nounwind
184 define void @test6_logical(i32 %a) {
185 ; CHECK-LABEL: @test6_logical(
186 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
187 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
188 ; CHECK-NEXT: br i1 [[TMP2]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
190 ; CHECK-NEXT: tail call void @foo() #[[ATTR0]]
191 ; CHECK-NEXT: ret void
193 ; CHECK-NEXT: ret void
195 %1 = icmp sgt i32 %a, -1
196 %and = and i32 %a, 134217728
197 %2 = icmp eq i32 %and, 0
198 %or.cond = select i1 %1, i1 %2, i1 false
199 br i1 %or.cond, label %if.then, label %if.end
203 tail call void @foo() nounwind
210 define void @test7(i32 %a) {
211 ; CHECK-LABEL: @test7(
212 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
213 ; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP1]], 0
214 ; CHECK-NEXT: br i1 [[DOTNOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
216 ; CHECK-NEXT: tail call void @foo() #[[ATTR0]]
217 ; CHECK-NEXT: ret void
219 ; CHECK-NEXT: ret void
221 %and = and i32 %a, 134217728
222 %1 = icmp ne i32 %and, 0
223 %2 = icmp slt i32 %a, 0
224 %or.cond = or i1 %1, %2
225 br i1 %or.cond, label %if.then, label %if.end
229 tail call void @foo() nounwind
236 define void @test7_logical(i32 %a) {
237 ; CHECK-LABEL: @test7_logical(
238 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
239 ; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP1]], 0
240 ; CHECK-NEXT: br i1 [[DOTNOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
242 ; CHECK-NEXT: tail call void @foo() #[[ATTR0]]
243 ; CHECK-NEXT: ret void
245 ; CHECK-NEXT: ret void
247 %and = and i32 %a, 134217728
248 %1 = icmp ne i32 %and, 0
249 %2 = icmp slt i32 %a, 0
250 %or.cond = select i1 %1, i1 true, i1 %2
251 br i1 %or.cond, label %if.then, label %if.end
255 tail call void @foo() nounwind
262 define void @test8(i32 %a) {
263 ; CHECK-LABEL: @test8(
264 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
265 ; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP1]], 0
266 ; CHECK-NEXT: br i1 [[DOTNOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
268 ; CHECK-NEXT: tail call void @foo()
269 ; CHECK-NEXT: ret void
271 ; CHECK-NEXT: ret void
273 %1 = icmp slt i32 %a, 0
274 %and = and i32 %a, 134217728
275 %2 = icmp ne i32 %and, 0
276 %or.cond = or i1 %1, %2
277 br i1 %or.cond, label %if.then, label %if.end
281 tail call void @foo()
288 define void @test8_logical(i32 %a) {
289 ; CHECK-LABEL: @test8_logical(
290 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -2013265920
291 ; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP1]], 0
292 ; CHECK-NEXT: br i1 [[DOTNOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
294 ; CHECK-NEXT: tail call void @foo()
295 ; CHECK-NEXT: ret void
297 ; CHECK-NEXT: ret void
299 %1 = icmp slt i32 %a, 0
300 %and = and i32 %a, 134217728
301 %2 = icmp ne i32 %and, 0
302 %or.cond = select i1 %1, i1 true, i1 %2
303 br i1 %or.cond, label %if.then, label %if.end
307 tail call void @foo()
314 define i1 @test9(i32 %a) {
315 ; CHECK-LABEL: @test9(
316 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -1073741824
317 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1073741824
318 ; CHECK-NEXT: ret i1 [[TMP2]]
320 %1 = and i32 %a, 1073741824
321 %2 = icmp ne i32 %1, 0
322 %3 = icmp sgt i32 %a, -1
323 %or.cond = and i1 %2, %3
327 define i1 @test9_logical(i32 %a) {
328 ; CHECK-LABEL: @test9_logical(
329 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -1073741824
330 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1073741824
331 ; CHECK-NEXT: ret i1 [[TMP2]]
333 %1 = and i32 %a, 1073741824
334 %2 = icmp ne i32 %1, 0
335 %3 = icmp sgt i32 %a, -1
336 %or.cond = select i1 %2, i1 %3, i1 false
340 define i1 @test10(i32 %a) {
341 ; CHECK-LABEL: @test10(
342 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[A:%.*]], 2
343 ; CHECK-NEXT: ret i1 [[TMP1]]
346 %2 = icmp eq i32 %1, 0
347 %3 = icmp ult i32 %a, 4
348 %or.cond = and i1 %2, %3
352 define i1 @test10_logical(i32 %a) {
353 ; CHECK-LABEL: @test10_logical(
354 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[A:%.*]], 2
355 ; CHECK-NEXT: ret i1 [[TMP1]]
358 %2 = icmp eq i32 %1, 0
359 %3 = icmp ult i32 %a, 4
360 %or.cond = select i1 %2, i1 %3, i1 false
364 define i1 @test11(i32 %a) {
365 ; CHECK-LABEL: @test11(
366 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
367 ; CHECK-NEXT: ret i1 [[TMP1]]
370 %2 = icmp ne i32 %1, 0
371 %3 = icmp ugt i32 %a, 3
372 %or.cond = or i1 %2, %3
376 define i1 @test11_logical(i32 %a) {
377 ; CHECK-LABEL: @test11_logical(
378 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
379 ; CHECK-NEXT: ret i1 [[TMP1]]
382 %2 = icmp ne i32 %1, 0
383 %3 = icmp ugt i32 %a, 3
384 %or.cond = select i1 %2, i1 true, i1 %3