1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -instcombine | FileCheck %s
3 ; RUN: opt -S < %s -passes=instcombine | FileCheck %s
5 define i1 @test_direct_implication(i1 %cond) {
6 ; CHECK-LABEL: @test_direct_implication(
8 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
10 ; CHECK-NEXT: br label [[MERGE:%.*]]
12 ; CHECK-NEXT: br label [[MERGE]]
14 ; CHECK-NEXT: ret i1 [[COND]]
17 br i1 %cond, label %if.true, label %if.false
26 %ret = phi i1 [true, %if.true], [false, %if.false]
30 define i1 @test_inverted_implication(i1 %cond) {
31 ; CHECK-LABEL: @test_inverted_implication(
33 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
35 ; CHECK-NEXT: br label [[MERGE:%.*]]
37 ; CHECK-NEXT: br label [[MERGE]]
39 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND]], true
40 ; CHECK-NEXT: ret i1 [[TMP0]]
43 br i1 %cond, label %if.true, label %if.false
52 %ret = phi i1 [false, %if.true], [true, %if.false]
56 define i1 @test_direct_implication_complex_cfg(i1 %cond, i32 %cnt1) {
57 ; CHECK-LABEL: @test_direct_implication_complex_cfg(
59 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
61 ; CHECK-NEXT: br label [[LOOP1:%.*]]
63 ; CHECK-NEXT: [[IV1:%.*]] = phi i32 [ 0, [[IF_TRUE]] ], [ [[IV1_NEXT:%.*]], [[LOOP1]] ]
64 ; CHECK-NEXT: [[IV1_NEXT]] = add i32 [[IV1]], 1
65 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = icmp slt i32 [[IV1_NEXT]], [[CNT1:%.*]]
66 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP1]], label [[IF_TRUE_END:%.*]]
68 ; CHECK-NEXT: br label [[MERGE:%.*]]
70 ; CHECK-NEXT: br label [[MERGE]]
72 ; CHECK-NEXT: ret i1 [[COND]]
75 br i1 %cond, label %if.true, label %if.false
81 %iv1 = phi i32 [0, %if.true], [%iv1.next, %loop1]
82 %iv1.next = add i32 %iv1, 1
83 %loop.cond.1 = icmp slt i32 %iv1.next, %cnt1
84 br i1 %loop.cond.1, label %loop1, label %if.true.end
93 %ret = phi i1 [true, %if.true.end], [false, %if.false]
97 define i1 @test_inverted_implication_complex_cfg(i1 %cond, i32 %cnt1) {
98 ; CHECK-LABEL: @test_inverted_implication_complex_cfg(
100 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
102 ; CHECK-NEXT: br label [[LOOP1:%.*]]
104 ; CHECK-NEXT: [[IV1:%.*]] = phi i32 [ 0, [[IF_TRUE]] ], [ [[IV1_NEXT:%.*]], [[LOOP1]] ]
105 ; CHECK-NEXT: [[IV1_NEXT]] = add i32 [[IV1]], 1
106 ; CHECK-NEXT: [[LOOP_COND_1:%.*]] = icmp slt i32 [[IV1_NEXT]], [[CNT1:%.*]]
107 ; CHECK-NEXT: br i1 [[LOOP_COND_1]], label [[LOOP1]], label [[IF_TRUE_END:%.*]]
108 ; CHECK: if.true.end:
109 ; CHECK-NEXT: br label [[MERGE:%.*]]
111 ; CHECK-NEXT: br label [[MERGE]]
113 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND]], true
114 ; CHECK-NEXT: ret i1 [[TMP0]]
117 br i1 %cond, label %if.true, label %if.false
123 %iv1 = phi i32 [0, %if.true], [%iv1.next, %loop1]
124 %iv1.next = add i32 %iv1, 1
125 %loop.cond.1 = icmp slt i32 %iv1.next, %cnt1
126 br i1 %loop.cond.1, label %loop1, label %if.true.end
135 %ret = phi i1 [false, %if.true.end], [true, %if.false]