1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
3 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
5 declare void @use(i32 %x)
8 define void @test_01(i32 %x, i32 %y) {
9 ; CHECK-LABEL: @test_01(
11 ; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
12 ; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[UNREACHED:%.*]]
14 ; CHECK-NEXT: [[C1:%.*]] = icmp ne i32 [[X]], [[Y]]
15 ; CHECK-NEXT: [[COMPARATOR:%.*]] = zext i1 [[C1]] to i32
16 ; CHECK-NEXT: call void @use(i32 [[COMPARATOR]])
17 ; CHECK-NEXT: unreachable
19 ; CHECK-NEXT: ret void
22 %c1 = icmp eq i32 %x, %y
23 %c2 = icmp slt i32 %x, %y
24 %signed = select i1 %c2, i32 -1, i32 1
25 %comparator = select i1 %c1, i32 0, i32 %signed
26 br i1 %c2, label %exit, label %unreached
29 call void @use(i32 %comparator)
37 define void @test_02(i32 %x, i32 %y) {
38 ; CHECK-LABEL: @test_02(
40 ; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
41 ; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[MEDIUM:%.*]]
43 ; CHECK-NEXT: [[C3:%.*]] = icmp sgt i32 [[X]], [[Y]]
44 ; CHECK-NEXT: br i1 [[C3]], label [[EXIT]], label [[UNREACHED:%.*]]
46 ; CHECK-NEXT: [[C1:%.*]] = icmp eq i32 [[X]], [[Y]]
47 ; CHECK-NEXT: [[SIGNED:%.*]] = select i1 [[C2]], i32 -1, i32 1
48 ; CHECK-NEXT: [[COMPARATOR:%.*]] = select i1 [[C1]], i32 0, i32 [[SIGNED]]
49 ; CHECK-NEXT: call void @use(i32 [[COMPARATOR]])
50 ; CHECK-NEXT: unreachable
52 ; CHECK-NEXT: ret void
55 %c1 = icmp eq i32 %x, %y
56 %c2 = icmp slt i32 %x, %y
57 %signed = select i1 %c2, i32 -1, i32 1
58 %comparator = select i1 %c1, i32 0, i32 %signed
59 br i1 %c2, label %exit, label %medium
62 %c3 = icmp sgt i32 %x, %y
63 br i1 %c3, label %exit, label %unreached
66 call void @use(i32 %comparator)
73 define i32 @test_03(i32 %x, i32 %y) {
74 ; CHECK-LABEL: @test_03(
76 ; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
77 ; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[MEDIUM:%.*]]
79 ; CHECK-NEXT: [[C3:%.*]] = icmp sgt i32 [[X]], [[Y]]
80 ; CHECK-NEXT: br i1 [[C3]], label [[EXIT]], label [[UNREACHED:%.*]]
82 ; CHECK-NEXT: [[C1:%.*]] = icmp eq i32 [[X]], [[Y]]
83 ; CHECK-NEXT: [[SIGNED:%.*]] = select i1 [[C2]], i32 -1, i32 1
84 ; CHECK-NEXT: [[COMPARATOR:%.*]] = select i1 [[C1]], i32 0, i32 [[SIGNED]]
85 ; CHECK-NEXT: ret i32 [[COMPARATOR]]
87 ; CHECK-NEXT: ret i32 0
90 %c1 = icmp eq i32 %x, %y
91 %c2 = icmp slt i32 %x, %y
92 %signed = select i1 %c2, i32 -1, i32 1
93 %comparator = select i1 %c1, i32 0, i32 %signed
94 br i1 %c2, label %exit, label %medium
97 %c3 = icmp sgt i32 %x, %y
98 br i1 %c3, label %exit, label %unreached
107 define i32 @test_04(i32 %x, i1 %c) {
108 ; CHECK-LABEL: @test_04(
110 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
112 ; CHECK-NEXT: br label [[BB3:%.*]]
114 ; CHECK-NEXT: br label [[BB3]]
116 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[BB1]] ], [ 1, [[BB2]] ]
117 ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 1
118 ; CHECK-NEXT: [[R:%.*]] = add i32 [[P]], [[A]]
119 ; CHECK-NEXT: ret i32 [[R]]
123 br i1 %c, label %bb1, label %bb2
129 %p = phi i32 [0, %bb1], [1, %bb2]
134 ; Do not sink into a potentially hotter block.
135 define i32 @test_05_neg(i32 %x, i1 %cond) {
136 ; CHECK-LABEL: @test_05_neg(
138 ; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 1
139 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
141 ; CHECK-NEXT: br label [[BB3:%.*]]
143 ; CHECK-NEXT: [[CALL:%.*]] = call i1 @cond()
144 ; CHECK-NEXT: br i1 [[CALL]], label [[BB2]], label [[BB3]]
146 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[BB1]] ], [ [[A]], [[BB2]] ]
147 ; CHECK-NEXT: ret i32 [[P]]
151 br i1 %cond, label %bb1, label %bb2
155 %call = call i1 @cond()
156 br i1 %call, label %bb2, label %bb3
158 %p = phi i32 [0, %bb1], [%a, %bb2]