1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @test_imply_not1(i32 %depth) {
5 ; CHECK-LABEL: define i1 @test_imply_not1(
6 ; CHECK-SAME: i32 [[DEPTH:%.*]]) {
7 ; CHECK-NEXT: [[CMP1_NOT1:%.*]] = icmp eq i32 [[DEPTH]], 16
8 ; CHECK-NEXT: call void @use(i1 [[CMP1_NOT1]])
9 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[DEPTH]], 8
10 ; CHECK-NEXT: call void @use(i1 [[CMP2]])
11 ; CHECK-NEXT: br i1 [[CMP1_NOT1]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]
13 ; CHECK-NEXT: call void @func1()
14 ; CHECK-NEXT: unreachable
16 ; CHECK-NEXT: call void @func2()
17 ; CHECK-NEXT: unreachable
19 %cmp1 = icmp eq i32 %depth, 16
20 call void @use(i1 %cmp1)
21 %cmp2 = icmp slt i32 %depth, 8
22 call void @use(i1 %cmp2)
23 %cmp.not = xor i1 %cmp1, true
24 %brmerge = or i1 %cmp2, %cmp.not
25 br i1 %brmerge, label %if.then, label %if.else
35 define i1 @test_imply_not2(i32 %a, i1 %cmp2) {
36 ; CHECK-LABEL: define i1 @test_imply_not2(
37 ; CHECK-SAME: i32 [[A:%.*]], i1 [[CMP2:%.*]]) {
38 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[A]], 0
39 ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]]
40 ; CHECK-NEXT: ret i1 [[BRMERGE]]
42 %cmp1 = icmp eq i32 %a, 0
43 %or.cond = select i1 %cmp1, i1 %cmp2, i1 false
44 %cmp.not = xor i1 %cmp1, true
45 %brmerge = or i1 %or.cond, %cmp.not
49 define i1 @test_imply_not3(i32 %a, i32 %b, i1 %cond) {
50 ; CHECK-LABEL: define i1 @test_imply_not3(
51 ; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]], i1 [[COND:%.*]]) {
52 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A]], [[B]]
53 ; CHECK-NEXT: call void @use(i1 [[CMP1]])
54 ; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[A]], [[B]]
55 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP2]], i1 [[COND]], i1 false
56 ; CHECK-NEXT: ret i1 [[AND]]
58 %cmp1 = icmp eq i32 %a, %b
59 call void @use(i1 %cmp1)
60 %cmp2 = icmp slt i32 %a, %b
61 %cmp.not = xor i1 %cmp1, true
62 %sel = select i1 %cmp.not, i1 %cond, i1 false
63 %and = and i1 %cmp2, %sel