1 ; Test the static branch probability heuristics for no-return functions.
2 ; RUN: opt < %s -passes='print<branch-prob>' --disable-output 2>&1 | FileCheck %s
10 define void @test1(i32 %a, i32 %b) {
13 ; CHECK: edge %entry -> %do.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
16 %i.0 = phi i32 [ 0, %entry ], [ %inc3, %do.end ]
19 ; CHECK: edge %do.body -> %do.body1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
22 %j.0 = phi i32 [ 0, %do.body ], [ %inc, %do.body1 ]
24 %inc = add nsw i32 %j.0, 1
25 %cmp = icmp slt i32 %inc, %b
26 br i1 %cmp, label %do.body1, label %do.end
27 ; CHECK: edge %do.body1 -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
28 ; CHECK: edge %do.body1 -> %do.end probability is 0x04000000 / 0x80000000 = 3.12%
32 %inc3 = add nsw i32 %i.0, 1
33 %cmp4 = icmp slt i32 %inc3, %a
34 br i1 %cmp4, label %do.body, label %do.end5
35 ; CHECK: edge %do.end -> %do.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
36 ; CHECK: edge %do.end -> %do.end5 probability is 0x04000000 / 0x80000000 = 3.12%
43 define void @test2(i32 %a, i32 %b) {
45 %cmp9 = icmp sgt i32 %a, 0
46 br i1 %cmp9, label %for.body.lr.ph, label %for.end6
47 ; CHECK: edge %entry -> %for.body.lr.ph probability is 0x50000000 / 0x80000000 = 62.50%
48 ; CHECK: edge %entry -> %for.end6 probability is 0x30000000 / 0x80000000 = 37.50%
51 %cmp27 = icmp sgt i32 %b, 0
53 ; CHECK: edge %for.body.lr.ph -> %for.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
56 %i.010 = phi i32 [ 0, %for.body.lr.ph ], [ %inc5, %for.end ]
58 br i1 %cmp27, label %for.body3, label %for.end
59 ; CHECK: edge %for.body -> %for.body3 probability is 0x50000000 / 0x80000000 = 62.50%
60 ; CHECK: edge %for.body -> %for.end probability is 0x30000000 / 0x80000000 = 37.50%
63 %j.08 = phi i32 [ %inc, %for.body3 ], [ 0, %for.body ]
65 %inc = add nsw i32 %j.08, 1
66 %exitcond = icmp eq i32 %inc, %b
67 br i1 %exitcond, label %for.end, label %for.body3
68 ; CHECK: edge %for.body3 -> %for.end probability is 0x04000000 / 0x80000000 = 3.12%
69 ; CHECK: edge %for.body3 -> %for.body3 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
73 %inc5 = add nsw i32 %i.010, 1
74 %exitcond11 = icmp eq i32 %inc5, %a
75 br i1 %exitcond11, label %for.end6, label %for.body
76 ; CHECK: edge %for.end -> %for.end6 probability is 0x04000000 / 0x80000000 = 3.12%
77 ; CHECK: edge %for.end -> %for.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
84 define void @test3(i32 %a, i32 %b, ptr %c) {
87 ; CHECK: edge %entry -> %do.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
90 %i.0 = phi i32 [ 0, %entry ], [ %inc4, %if.end ]
92 %0 = load i32, ptr %c, align 4
93 %cmp = icmp slt i32 %0, 42
94 br i1 %cmp, label %do.body1, label %if.end
95 ; CHECK: edge %do.body -> %do.body1 probability is 0x40000000 / 0x80000000 = 50.00%
96 ; CHECK: edge %do.body -> %if.end probability is 0x40000000 / 0x80000000 = 50.00%
99 %j.0 = phi i32 [ %inc, %do.body1 ], [ 0, %do.body ]
101 %inc = add nsw i32 %j.0, 1
102 %cmp2 = icmp slt i32 %inc, %b
103 br i1 %cmp2, label %do.body1, label %if.end
104 ; CHECK: edge %do.body1 -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
105 ; CHECK: edge %do.body1 -> %if.end probability is 0x04000000 / 0x80000000 = 3.12%
109 %inc4 = add nsw i32 %i.0, 1
110 %cmp5 = icmp slt i32 %inc4, %a
111 br i1 %cmp5, label %do.body, label %do.end6
112 ; CHECK: edge %if.end -> %do.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
113 ; CHECK: edge %if.end -> %do.end6 probability is 0x04000000 / 0x80000000 = 3.12%
120 define void @test4(i32 %a, i32 %b, ptr %c) {
123 ; CHECK: edge %entry -> %do.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
126 %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ]
128 %0 = load i32, ptr %c, align 4
129 %cmp = icmp slt i32 %0, 42
130 br i1 %cmp, label %return, label %do.body1
131 ; CHECK: edge %do.body -> %return probability is 0x04000000 / 0x80000000 = 3.12%
132 ; CHECK: edge %do.body -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
135 %j.0 = phi i32 [ %inc, %do.body1 ], [ 0, %do.body ]
137 %inc = add nsw i32 %j.0, 1
138 %cmp2 = icmp slt i32 %inc, %b
139 br i1 %cmp2, label %do.body1, label %do.end
140 ; CHECK: edge %do.body1 -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
141 ; CHECK: edge %do.body1 -> %do.end probability is 0x04000000 / 0x80000000 = 3.12%
145 %inc4 = add nsw i32 %i.0, 1
146 %cmp5 = icmp slt i32 %inc4, %a
147 br i1 %cmp5, label %do.body, label %do.end6
148 ; CHECK: edge %do.end -> %do.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
149 ; CHECK: edge %do.end -> %do.end6 probability is 0x04000000 / 0x80000000 = 3.12%
154 ; CHECK: edge %do.end6 -> %return probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
160 define void @test5(i32 %a, i32 %b, ptr %c) {
163 ; CHECK: edge %entry -> %do.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
166 %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ]
169 ; CHECK: edge %do.body -> %do.body1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
172 %j.0 = phi i32 [ 0, %do.body ], [ %inc, %if.end ]
173 %0 = load i32, ptr %c, align 4
174 %cmp = icmp slt i32 %0, 42
175 br i1 %cmp, label %return, label %if.end
176 ; CHECK: edge %do.body1 -> %return probability is 0x04000000 / 0x80000000 = 3.12%
177 ; CHECK: edge %do.body1 -> %if.end probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
181 %inc = add nsw i32 %j.0, 1
182 %cmp2 = icmp slt i32 %inc, %b
183 br i1 %cmp2, label %do.body1, label %do.end
184 ; CHECK: edge %if.end -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
185 ; CHECK: edge %if.end -> %do.end probability is 0x04000000 / 0x80000000 = 3.12%
189 %inc4 = add nsw i32 %i.0, 1
190 %cmp5 = icmp slt i32 %inc4, %a
191 br i1 %cmp5, label %do.body, label %do.end6
192 ; CHECK: edge %do.end -> %do.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
193 ; CHECK: edge %do.end -> %do.end6 probability is 0x04000000 / 0x80000000 = 3.12%
198 ; CHECK: edge %do.end6 -> %return probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
204 define void @test6(i32 %a, i32 %b, ptr %c) {
207 ; CHECK: edge %entry -> %do.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
210 %i.0 = phi i32 [ 0, %entry ], [ %inc4, %do.end ]
213 ; CHECK: edge %do.body -> %do.body1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
216 %j.0 = phi i32 [ 0, %do.body ], [ %inc, %do.cond ]
218 %0 = load i32, ptr %c, align 4
219 %cmp = icmp slt i32 %0, 42
220 br i1 %cmp, label %return, label %do.cond
221 ; CHECK: edge %do.body1 -> %return probability is 0x04000000 / 0x80000000 = 3.12%
222 ; CHECK: edge %do.body1 -> %do.cond probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
225 %inc = add nsw i32 %j.0, 1
226 %cmp2 = icmp slt i32 %inc, %b
227 br i1 %cmp2, label %do.body1, label %do.end
228 ; CHECK: edge %do.cond -> %do.body1 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
229 ; CHECK: edge %do.cond -> %do.end probability is 0x04000000 / 0x80000000 = 3.12%
233 %inc4 = add nsw i32 %i.0, 1
234 %cmp5 = icmp slt i32 %inc4, %a
235 br i1 %cmp5, label %do.body, label %do.end6
236 ; CHECK: edge %do.end -> %do.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
237 ; CHECK: edge %do.end -> %do.end6 probability is 0x04000000 / 0x80000000 = 3.12%
242 ; CHECK: edge %do.end6 -> %return probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
248 define void @test7(i32 %a, i32 %b, ptr %c) {
250 %cmp10 = icmp sgt i32 %a, 0
251 br i1 %cmp10, label %for.body.lr.ph, label %for.end7
252 ; CHECK: edge %entry -> %for.body.lr.ph probability is 0x50000000 / 0x80000000 = 62.50%
253 ; CHECK: edge %entry -> %for.end7 probability is 0x30000000 / 0x80000000 = 37.50%
256 %cmp38 = icmp sgt i32 %b, 0
258 ; CHECK: edge %for.body.lr.ph -> %for.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
261 %i.011 = phi i32 [ 0, %for.body.lr.ph ], [ %inc6, %for.inc5 ]
262 %0 = load i32, ptr %c, align 4
263 %cmp1 = icmp eq i32 %0, %i.011
264 br i1 %cmp1, label %for.inc5, label %if.end
265 ; CHECK: edge %for.body -> %for.inc5 probability is 0x40000000 / 0x80000000 = 50.00%
266 ; CHECK: edge %for.body -> %if.end probability is 0x40000000 / 0x80000000 = 50.00%
270 br i1 %cmp38, label %for.body4, label %for.end
271 ; CHECK: edge %if.end -> %for.body4 probability is 0x50000000 / 0x80000000 = 62.50%
272 ; CHECK: edge %if.end -> %for.end probability is 0x30000000 / 0x80000000 = 37.50%
275 %j.09 = phi i32 [ %inc, %for.body4 ], [ 0, %if.end ]
277 %inc = add nsw i32 %j.09, 1
278 %exitcond = icmp eq i32 %inc, %b
279 br i1 %exitcond, label %for.end, label %for.body4
280 ; CHECK: edge %for.body4 -> %for.end probability is 0x04000000 / 0x80000000 = 3.12%
281 ; CHECK: edge %for.body4 -> %for.body4 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
286 ; CHECK: edge %for.end -> %for.inc5 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
289 %inc6 = add nsw i32 %i.011, 1
290 %exitcond12 = icmp eq i32 %inc6, %a
291 br i1 %exitcond12, label %for.end7, label %for.body
292 ; CHECK: edge %for.inc5 -> %for.end7 probability is 0x04000000 / 0x80000000 = 3.12%
293 ; CHECK: edge %for.inc5 -> %for.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
300 define void @test8(i32 %a, i32 %b, ptr %c) {
302 %cmp18 = icmp sgt i32 %a, 0
303 br i1 %cmp18, label %for.body.lr.ph, label %for.end15
304 ; CHECK: edge %entry -> %for.body.lr.ph probability is 0x50000000 / 0x80000000 = 62.50%
305 ; CHECK: edge %entry -> %for.end15 probability is 0x30000000 / 0x80000000 = 37.50%
308 %cmp216 = icmp sgt i32 %b, 0
309 %arrayidx5 = getelementptr inbounds i32, ptr %c, i64 1
310 %arrayidx9 = getelementptr inbounds i32, ptr %c, i64 2
312 ; CHECK: edge %for.body.lr.ph -> %for.body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
315 %i.019 = phi i32 [ 0, %for.body.lr.ph ], [ %inc14, %for.end ]
317 br i1 %cmp216, label %for.body3, label %for.end
318 ; CHECK: edge %for.body -> %for.body3 probability is 0x50000000 / 0x80000000 = 62.50%
319 ; CHECK: edge %for.body -> %for.end probability is 0x30000000 / 0x80000000 = 37.50%
322 %j.017 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ]
323 %0 = load i32, ptr %c, align 4
324 %cmp4 = icmp eq i32 %0, %j.017
325 br i1 %cmp4, label %for.inc, label %if.end
326 ; CHECK: edge %for.body3 -> %for.inc probability is 0x40000000 / 0x80000000 = 50.00%
327 ; CHECK: edge %for.body3 -> %if.end probability is 0x40000000 / 0x80000000 = 50.00%
330 %1 = load i32, ptr %arrayidx5, align 4
331 %cmp6 = icmp eq i32 %1, %j.017
332 br i1 %cmp6, label %for.inc, label %if.end8
333 ; CHECK: edge %if.end -> %for.inc probability is 0x40000000 / 0x80000000 = 50.00%
334 ; CHECK: edge %if.end -> %if.end8 probability is 0x40000000 / 0x80000000 = 50.00%
337 %2 = load i32, ptr %arrayidx9, align 4
338 %cmp10 = icmp eq i32 %2, %j.017
339 br i1 %cmp10, label %for.inc, label %if.end12
340 ; CHECK: edge %if.end8 -> %for.inc probability is 0x40000000 / 0x80000000 = 50.00%
341 ; CHECK: edge %if.end8 -> %if.end12 probability is 0x40000000 / 0x80000000 = 50.00%
346 ; CHECK: edge %if.end12 -> %for.inc probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
349 %inc = add nsw i32 %j.017, 1
350 %exitcond = icmp eq i32 %inc, %b
351 br i1 %exitcond, label %for.end, label %for.body3
352 ; CHECK: edge %for.inc -> %for.end probability is 0x04000000 / 0x80000000 = 3.12%
353 ; CHECK: edge %for.inc -> %for.body3 probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
357 %inc14 = add nsw i32 %i.019, 1
358 %exitcond20 = icmp eq i32 %inc14, %a
359 br i1 %exitcond20, label %for.end15, label %for.body
360 ; CHECK: edge %for.end -> %for.end15 probability is 0x04000000 / 0x80000000 = 3.12%
361 ; CHECK: edge %for.end -> %for.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
368 ; Test that an irreducible loop gets heavily weighted back-edges.
369 define void @test9(i32 %i, i32 %x, i32 %c) {
371 %tobool = icmp eq i32 %c, 0
372 br i1 %tobool, label %if.end, label %midloop
373 ; CHECK: edge %entry -> %if.end probability is 0x30000000 / 0x80000000 = 37.50%
374 ; CHECK: edge %entry -> %midloop probability is 0x50000000 / 0x80000000 = 62.50%
378 ; CHECK: edge %if.end -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
381 %i.addr.0 = phi i32 [ %inc, %for.inc ], [ 0, %if.end ]
382 %cmp = icmp slt i32 %i.addr.0, %x
383 br i1 %cmp, label %midloop, label %end
384 ; CHECK: edge %for.cond -> %midloop probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
385 ; CHECK: edge %for.cond -> %end probability is 0x04000000 / 0x80000000 = 3.12%
388 %i.addr.1 = phi i32 [ %i, %entry ], [ %i.addr.0, %for.cond ]
389 %call1 = call i32 @g5()
390 %tobool2 = icmp eq i32 %call1, 0
391 br i1 %tobool2, label %for.inc, label %end
392 ; CHECK: edge %midloop -> %for.inc probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
393 ; CHECK: edge %midloop -> %end probability is 0x04000000 / 0x80000000 = 3.12%
396 %inc = add nsw i32 %i.addr.1, 1
398 ; CHECK: edge %for.inc -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
404 ; Check that the for.body -> if.then edge is considered unlikely due to making
405 ; the if-condition false for the next iteration of the loop.
406 define i32 @test10(i32 %n, ptr %p) {
409 ; CHECK: edge %entry -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
412 %count.0 = phi i32 [ 0, %entry ], [ %count.1, %for.inc ]
413 %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.inc ]
414 %i.0 = phi i32 [ 0, %entry ], [ %inc3, %for.inc ]
415 %cmp = icmp slt i32 %i.0, %n
416 br i1 %cmp, label %for.body, label %for.cond.cleanup
417 ; CHECK: edge %for.cond -> %for.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
418 ; CHECK: edge %for.cond -> %for.cond.cleanup probability is 0x04000000 / 0x80000000 = 3.12%
424 %arrayidx = getelementptr inbounds i32, ptr %p, i32 %i.0
425 %0 = load i32, ptr %arrayidx, align 4
426 %add = add nsw i32 %sum.0, %0
427 %inc = add nsw i32 %count.0, 1
428 %cmp1 = icmp sgt i32 %count.0, 6
429 br i1 %cmp1, label %if.then, label %for.inc
430 ; CHECK: edge %for.body -> %if.then probability is 0x2aaaa8e4 / 0x80000000 = 33.33%
431 ; CHECK: edge %for.body -> %for.inc probability is 0x5555571c / 0x80000000 = 66.67%
433 store i32 %add, ptr %arrayidx, align 4
435 ; CHECK: edge %if.then -> %for.inc probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
438 %count.1 = phi i32 [ 0, %if.then ], [ %inc, %for.body ]
439 %sum.1 = phi i32 [ 0, %if.then ], [ %add, %for.body ]
440 %inc3 = add nsw i32 %i.0, 1
442 ; CHECK: edge %for.inc -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
445 ; Each successor to for.body makes itself not be taken in the next iteration, so
446 ; both should be equally likely
447 define i32 @test11(i32 %n, ptr %p) {
450 ; CHECK: edge %entry -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
453 %flip.0 = phi i32 [ 0, %entry ], [ %flip.1, %for.inc ]
454 %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.inc ]
455 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
456 %cmp = icmp slt i32 %i.0, %n
457 br i1 %cmp, label %for.body, label %for.cond.cleanup
458 ; CHECK: edge %for.cond -> %for.body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
459 ; CHECK: edge %for.cond -> %for.cond.cleanup probability is 0x04000000 / 0x80000000 = 3.12%
465 %tobool = icmp eq i32 %flip.0, 0
466 %arrayidx1 = getelementptr inbounds i32, ptr %p, i32 %i.0
467 %0 = load i32, ptr %arrayidx1, align 4
468 br i1 %tobool, label %if.else, label %if.then
469 ; CHECK: edge %for.body -> %if.else probability is 0x40000000 / 0x80000000 = 50.00%
470 ; CHECK: edge %for.body -> %if.then probability is 0x40000000 / 0x80000000 = 50.00%
473 %add = add nsw i32 %0, %sum.0
474 store i32 %add, ptr %arrayidx1, align 4
476 ; CHECK: edge %if.then -> %for.inc probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
479 %add2 = add nsw i32 %sum.0, %0
481 ; CHECK: edge %if.else -> %for.inc probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
484 %flip.1 = phi i32 [ 0, %if.then ], [ 1, %if.else ]
485 %sum.1 = phi i32 [ %sum.0, %if.then ], [ %add2, %if.else ]
486 %inc = add nsw i32 %i.0, 1
488 ; CHECK: edge %for.inc -> %for.cond probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
491 ; The loop heuristic should not overwrite the invoke heuristic. The unwind destination
492 ; of an invoke should be considered VERY rare even in a loop.
493 define void @test12(i32 %a) personality i8 0 {
496 ; CHECK: edge %entry -> %loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
499 %i.0 = phi i32 [ 0, %entry ], [ %inc, %invoke.cont ]
500 invoke i32 @InvokeCall()
501 to label %invoke.cont unwind label %lpad
502 ; CHECK: edge %loop -> %invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
503 ; CHECK: edge %loop -> %lpad probability is 0x00000800 / 0x80000000 = 0.00%
506 %inc = add nsw i32 %i.0, 1
507 %cmp = icmp slt i32 %inc, %a
508 br i1 %cmp, label %loop, label %exit
509 ; CHECK: edge %invoke.cont -> %loop probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
510 ; CHECK: edge %invoke.cont -> %exit probability is 0x04000000 / 0x80000000 = 3.12%
513 %ll = landingpad { ptr, i32 }
521 declare i32 @InvokeCall()
522 declare void @cold() cold
524 ; If loop has single exit and it leads to 'cold' block then edge leading to loop enter
525 ; should be considered 'cold' as well.
526 define void @test13() {
527 ; CHECK: edge %entry -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
528 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
529 ; CHECK: edge %loop -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
530 ; CHECK: edge %loop -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
531 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
534 br i1 undef, label %loop, label %exit
537 %i.0 = phi i32 [ 0, %entry ], [ %inc, %loop ]
538 %inc = add nsw i32 %i.0, 1
539 br i1 undef, label %loop, label %cold
549 ; This is the same case as test13 but with additional loop 'preheader' block.
550 define void @test14() {
551 ; CHECK: edge %entry -> %preheader probability is 0x078780e3 / 0x80000000 = 5.88%
552 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
553 ; CHECK: edge %preheader -> %loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
554 ; CHECK: edge %loop -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
555 ; CHECK: edge %loop -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
556 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
559 br i1 undef, label %preheader, label %exit
565 %i.0 = phi i32 [ 0, %preheader ], [ %inc, %loop ]
566 %inc = add nsw i32 %i.0, 1
567 br i1 undef, label %loop, label %cold
577 ; If loop has multiple low probability exits then edge leading to loop enter
578 ; should be considered low probable as well.
579 define void @test15() {
580 ; CHECK: edge %entry -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
581 ; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
582 ; CHECK: edge %loop -> %cont probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
583 ; CHECK: edge %loop -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
584 ; CHECK: edge %cont -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
585 ; CHECK: edge %cont -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
586 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
589 br i1 undef, label %loop, label %exit
592 %i.0 = phi i32 [ 0, %entry ], [ %inc, %cont ]
593 %inc = add nsw i32 %i.0, 1
594 br i1 undef, label %cont, label %unreached
597 br i1 undef, label %loop, label %cold
611 ; This is the same case as test15 but with additional loop 'preheader' block.
612 define void @test16() {
613 ; CHECK: edge %entry -> %preheader probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
614 ; CHECK: edge %preheader -> %loop probability is 0x078780e3 / 0x80000000 = 5.88%
615 ; CHECK: edge %preheader -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
616 ; CHECK: edge %loop -> %cont probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
617 ; CHECK: edge %loop -> %unreached probability is 0x00000000 / 0x80000000 = 0.00%
618 ; CHECK: edge %cont -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
619 ; CHECK: edge %cont -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
620 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
626 br i1 undef, label %loop, label %exit
629 %i.0 = phi i32 [ 0, %preheader ], [ %inc, %cont ]
630 %inc = add nsw i32 %i.0, 1
631 br i1 undef, label %cont, label %unreached
634 br i1 undef, label %loop, label %cold
648 declare void @abort() noreturn
650 ; Check that 'preheader' has 50/50 probability since there is one 'normal' exit.
651 ; Check that exit to 'cold' and 'noreturn' has lower probability than 'normal' exit.
652 define void @test17() {
653 ; CHECK: edge %entry -> %preheader probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
654 ; CHECK: edge %preheader -> %loop probability is 0x40000000 / 0x80000000 = 50.00%
655 ; CHECK: edge %preheader -> %exit probability is 0x40000000 / 0x80000000 = 50.00%
656 ; CHECK: edge %loop -> %cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
657 ; CHECK: edge %loop -> %noreturn probability is 0x00000800 / 0x80000000 = 0.00%
658 ; CHECK: edge %cont -> %cont2 probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
659 ; CHECK: edge %cont -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
660 ; CHECK: edge %cont2 -> %loop probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
661 ; CHECK: edge %cont2 -> %exit probability is 0x04000000 / 0x80000000 = 3.12%
662 ; CHECK: edge %cold -> %exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
667 br i1 undef, label %loop, label %exit
670 %i.0 = phi i32 [ 0, %preheader ], [ %inc, %cont2 ]
671 %inc = add nsw i32 %i.0, 1
672 br i1 undef, label %cont, label %noreturn
675 br i1 undef, label %cont2, label %cold
678 br i1 undef, label %loop, label %exit
693 ; This is case with two loops where one nested into another. Nested loop has
694 ; low probable exit what encreases robability to take exit in the top level loop.
695 define void @test18() {
696 ; CHECK: edge %entry -> %top.loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
697 ; CHECK: edge %top.loop -> %loop probability is 0x546cd4b7 / 0x80000000 = 65.96%
698 ; CHECK: edge %top.loop -> %exit probability is 0x2b932b49 / 0x80000000 = 34.04%
699 ; CHECK: edge %loop -> %loop probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
700 ; CHECK: edge %loop -> %cold probability is 0x0041edfd / 0x80000000 = 0.20%
701 ; CHECK: edge %cold -> %top.loop probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
707 %j.0 = phi i32 [ 0, %entry ], [ %j.inc, %cold ]
708 br i1 undef, label %loop, label %exit
711 %i.0 = phi i32 [ %j.0, %top.loop ], [ %inc, %loop ]
712 %inc = add nsw i32 %i.0, 1
713 br i1 undef, label %loop, label %cold
717 %j.inc = add nsw i32 %j.0, 1