1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -S -simplifycfg | FileCheck %s
7 define void @test_and1(i32 %a, i32 %b) {
8 ; CHECK-LABEL: @test_and1(
10 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], 0
11 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0
12 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
13 ; CHECK-NEXT: br i1 [[AND]], label [[TAKEN:%.*]], label [[END:%.*]]
15 ; CHECK-NEXT: call void @bar()
16 ; CHECK-NEXT: call void @foo()
17 ; CHECK-NEXT: br label [[END]]
19 ; CHECK-NEXT: ret void
22 %cmp1 = icmp eq i32 %a, 0
23 %cmp2 = icmp eq i32 %b, 0
24 %and = and i1 %cmp1, %cmp2
25 br i1 %and, label %taken, label %end
29 %cmp3 = icmp eq i32 %a, 0 ;; <-- implied true
30 br i1 %cmp3, label %if.then, label %end
40 ; We can't infer anything if the result of the 'and' is false
42 define void @test_and2(i32 %a, i32 %b) {
43 ; CHECK-LABEL: @test_and2(
45 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], 0
46 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0
47 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP1]], [[CMP2]]
48 ; CHECK-NEXT: br i1 [[AND]], label [[END:%.*]], label [[TAKEN:%.*]]
50 ; CHECK-NEXT: call void @bar()
51 ; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i32 [[A]], 0
52 ; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN:%.*]], label [[END]]
54 ; CHECK-NEXT: call void @foo()
55 ; CHECK-NEXT: br label [[END]]
57 ; CHECK-NEXT: ret void
60 %cmp1 = icmp eq i32 %a, 0
61 %cmp2 = icmp eq i32 %b, 0
62 %and = and i1 %cmp1, %cmp2
63 br i1 %and, label %end, label %taken
67 %cmp3 = icmp eq i32 %a, 0
68 br i1 %cmp3, label %if.then, label %end
78 define void @test_or1(i32 %a, i32 %b) {
79 ; CHECK-LABEL: @test_or1(
81 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], 0
82 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0
83 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP1]], [[CMP2]]
84 ; CHECK-NEXT: br i1 [[OR]], label [[END:%.*]], label [[TAKEN:%.*]]
86 ; CHECK-NEXT: call void @bar()
87 ; CHECK-NEXT: call void @foo()
88 ; CHECK-NEXT: br label [[END]]
90 ; CHECK-NEXT: ret void
93 %cmp1 = icmp eq i32 %a, 0
94 %cmp2 = icmp eq i32 %b, 0
95 %or = or i1 %cmp1, %cmp2
96 br i1 %or, label %end, label %taken
100 %cmp3 = icmp ne i32 %a, 0 ;; <-- implied true
101 br i1 %cmp3, label %if.then, label %end
111 ; We can't infer anything if the result of the 'or' is true
113 define void @test_or2(i32 %a, i32 %b) {
114 ; CHECK-LABEL: @test_or2(
116 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], 0
117 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0
118 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP1]], [[CMP2]]
119 ; CHECK-NEXT: br i1 [[OR]], label [[TAKEN:%.*]], label [[END:%.*]]
121 ; CHECK-NEXT: call void @bar()
122 ; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i32 [[A]], 0
123 ; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN:%.*]], label [[END]]
125 ; CHECK-NEXT: call void @foo()
126 ; CHECK-NEXT: br label [[END]]
128 ; CHECK-NEXT: ret void
131 %cmp1 = icmp eq i32 %a, 0
132 %cmp2 = icmp eq i32 %b, 0
133 %or = or i1 %cmp1, %cmp2
134 br i1 %or, label %taken, label %end
138 %cmp3 = icmp eq i32 %a, 0
139 br i1 %cmp3, label %if.then, label %end
149 ; We can recurse a tree of 'and' or 'or's.
151 define void @test_and_recurse1(i32 %a, i32 %b, i32 %c) {
152 ; CHECK-LABEL: @test_and_recurse1(
154 ; CHECK-NEXT: [[CMPA:%.*]] = icmp eq i32 [[A:%.*]], 0
155 ; CHECK-NEXT: [[CMPB:%.*]] = icmp eq i32 [[B:%.*]], 0
156 ; CHECK-NEXT: [[CMPC:%.*]] = icmp eq i32 [[C:%.*]], 0
157 ; CHECK-NEXT: [[AND1:%.*]] = and i1 [[CMPA]], [[CMPB]]
158 ; CHECK-NEXT: [[AND2:%.*]] = and i1 [[AND1]], [[CMPC]]
159 ; CHECK-NEXT: br i1 [[AND2]], label [[TAKEN:%.*]], label [[END:%.*]]
161 ; CHECK-NEXT: call void @bar()
162 ; CHECK-NEXT: call void @foo()
163 ; CHECK-NEXT: br label [[END]]
165 ; CHECK-NEXT: ret void
168 %cmpa = icmp eq i32 %a, 0
169 %cmpb = icmp eq i32 %b, 0
170 %cmpc = icmp eq i32 %c, 0
171 %and1 = and i1 %cmpa, %cmpb
172 %and2 = and i1 %and1, %cmpc
173 br i1 %and2, label %taken, label %end
177 %cmp3 = icmp eq i32 %a, 0
178 br i1 %cmp3, label %if.then, label %end
188 ; Check to make sure we don't recurse too deep.
190 define void @test_and_recurse2(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f,
191 ; CHECK-LABEL: @test_and_recurse2(
193 ; CHECK-NEXT: [[CMPA:%.*]] = icmp eq i32 [[A:%.*]], 0
194 ; CHECK-NEXT: [[CMPB:%.*]] = icmp eq i32 [[B:%.*]], 0
195 ; CHECK-NEXT: [[CMPC:%.*]] = icmp eq i32 [[C:%.*]], 0
196 ; CHECK-NEXT: [[CMPD:%.*]] = icmp eq i32 [[D:%.*]], 0
197 ; CHECK-NEXT: [[CMPE:%.*]] = icmp eq i32 [[E:%.*]], 0
198 ; CHECK-NEXT: [[CMPF:%.*]] = icmp eq i32 [[F:%.*]], 0
199 ; CHECK-NEXT: [[CMPG:%.*]] = icmp eq i32 [[G:%.*]], 0
200 ; CHECK-NEXT: [[CMPH:%.*]] = icmp eq i32 [[H:%.*]], 0
201 ; CHECK-NEXT: [[AND1:%.*]] = and i1 [[CMPA]], [[CMPB]]
202 ; CHECK-NEXT: [[AND2:%.*]] = and i1 [[AND1]], [[CMPC]]
203 ; CHECK-NEXT: [[AND3:%.*]] = and i1 [[AND2]], [[CMPD]]
204 ; CHECK-NEXT: [[AND4:%.*]] = and i1 [[AND3]], [[CMPE]]
205 ; CHECK-NEXT: [[AND5:%.*]] = and i1 [[AND4]], [[CMPF]]
206 ; CHECK-NEXT: [[AND6:%.*]] = and i1 [[AND5]], [[CMPG]]
207 ; CHECK-NEXT: [[AND7:%.*]] = and i1 [[AND6]], [[CMPH]]
208 ; CHECK-NEXT: br i1 [[AND7]], label [[TAKEN:%.*]], label [[END:%.*]]
210 ; CHECK-NEXT: call void @bar()
211 ; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i32 [[A]], 0
212 ; CHECK-NEXT: br i1 [[CMP3]], label [[IF_THEN:%.*]], label [[END]]
214 ; CHECK-NEXT: call void @foo()
215 ; CHECK-NEXT: br label [[END]]
217 ; CHECK-NEXT: ret void
221 %cmpa = icmp eq i32 %a, 0
222 %cmpb = icmp eq i32 %b, 0
223 %cmpc = icmp eq i32 %c, 0
224 %cmpd = icmp eq i32 %d, 0
225 %cmpe = icmp eq i32 %e, 0
226 %cmpf = icmp eq i32 %f, 0
227 %cmpg = icmp eq i32 %g, 0
228 %cmph = icmp eq i32 %h, 0
229 %and1 = and i1 %cmpa, %cmpb
230 %and2 = and i1 %and1, %cmpc
231 %and3 = and i1 %and2, %cmpd
232 %and4 = and i1 %and3, %cmpe
233 %and5 = and i1 %and4, %cmpf
234 %and6 = and i1 %and5, %cmpg
235 %and7 = and i1 %and6, %cmph
236 br i1 %and7, label %taken, label %end
240 %cmp3 = icmp eq i32 %a, 0 ; <-- can be implied true
241 br i1 %cmp3, label %if.then, label %end