1; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
2
3define i32 @test1(i32 %i, i32* %a) {
4; CHECK: Printing analysis {{.*}} for function 'test1'
5entry:
6  br label %body
7; CHECK: edge entry -> body probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
8
9body:
10  %iv = phi i32 [ 0, %entry ], [ %next, %body ]
11  %base = phi i32 [ 0, %entry ], [ %sum, %body ]
12  %arrayidx = getelementptr inbounds i32, i32* %a, i32 %iv
13  %0 = load i32, i32* %arrayidx
14  %sum = add nsw i32 %0, %base
15  %next = add i32 %iv, 1
16  %exitcond = icmp eq i32 %next, %i
17  br i1 %exitcond, label %exit, label %body
18; CHECK: edge body -> exit probability is 0x04000000 / 0x80000000 = 3.12%
19; CHECK: edge body -> body probability is 0x7c000000 / 0x80000000 = 96.88% [HOT edge]
20
21exit:
22  ret i32 %sum
23}
24
25define i32 @test2(i32 %i, i32 %a, i32 %b) {
26; CHECK: Printing analysis {{.*}} for function 'test2'
27entry:
28  %cond = icmp ult i32 %i, 42
29  br i1 %cond, label %then, label %else, !prof !0
30; CHECK: edge entry -> then probability is 0x78787878 / 0x80000000 = 94.12% [HOT edge]
31; CHECK: edge entry -> else probability is 0x07878788 / 0x80000000 = 5.88%
32
33then:
34  br label %exit
35; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
36
37else:
38  br label %exit
39; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
40
41exit:
42  %result = phi i32 [ %a, %then ], [ %b, %else ]
43  ret i32 %result
44}
45
46!0 = !{!"branch_weights", i32 64, i32 4}
47
48define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
49; CHECK: Printing analysis {{.*}} for function 'test3'
50entry:
51  switch i32 %i, label %case_a [ i32 1, label %case_b
52                                 i32 2, label %case_c
53                                 i32 3, label %case_d
54                                 i32 4, label %case_e ], !prof !1
55; CHECK: edge entry -> case_a probability is 0x06666666 / 0x80000000 = 5.00%
56; CHECK: edge entry -> case_b probability is 0x06666666 / 0x80000000 = 5.00%
57; CHECK: edge entry -> case_c probability is 0x66666666 / 0x80000000 = 80.00%
58; CHECK: edge entry -> case_d probability is 0x06666666 / 0x80000000 = 5.00%
59; CHECK: edge entry -> case_e probability is 0x06666666 / 0x80000000 = 5.00%
60
61case_a:
62  br label %exit
63; CHECK: edge case_a -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
64
65case_b:
66  br label %exit
67; CHECK: edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
68
69case_c:
70  br label %exit
71; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
72
73case_d:
74  br label %exit
75; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
76
77case_e:
78  br label %exit
79; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
80
81exit:
82  %result = phi i32 [ %a, %case_a ],
83                    [ %b, %case_b ],
84                    [ %c, %case_c ],
85                    [ %d, %case_d ],
86                    [ %e, %case_e ]
87  ret i32 %result
88}
89
90!1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
91
92define i32 @test4(i32 %x) nounwind uwtable readnone ssp {
93; CHECK: Printing analysis {{.*}} for function 'test4'
94entry:
95  %conv = sext i32 %x to i64
96  switch i64 %conv, label %return [
97    i64 0, label %sw.bb
98    i64 1, label %sw.bb
99    i64 2, label %sw.bb
100    i64 5, label %sw.bb1
101  ], !prof !2
102; CHECK: edge entry -> return probability is 0x0a8a8a8b / 0x80000000 = 8.24%
103; CHECK: edge entry -> sw.bb probability is 0x15151515 / 0x80000000 = 16.47%
104; CHECK: edge entry -> sw.bb1 probability is 0x60606060 / 0x80000000 = 75.29%
105
106sw.bb:
107  br label %return
108
109sw.bb1:
110  br label %return
111
112return:
113  %retval.0 = phi i32 [ 5, %sw.bb1 ], [ 1, %sw.bb ], [ 0, %entry ]
114  ret i32 %retval.0
115}
116
117!2 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 4, i32 64}
118
119declare void @coldfunc() cold
120
121define i32 @test5(i32 %a, i32 %b, i1 %flag) {
122; CHECK: Printing analysis {{.*}} for function 'test5'
123entry:
124  br i1 %flag, label %then, label %else
125; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
126; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
127
128then:
129  call void @coldfunc()
130  br label %exit
131; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
132
133else:
134  br label %exit
135; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
136
137exit:
138  %result = phi i32 [ %a, %then ], [ %b, %else ]
139  ret i32 %result
140}
141
142define i32 @test_cold_loop(i32 %a, i32 %b) {
143entry:
144  %cond1 = icmp eq i32 %a, 42
145  br i1 %cond1, label %header, label %exit
146; CHECK: edge entry -> header probability is 0x40000000 / 0x80000000 = 50.00%
147; CHECK: edge entry -> exit probability is 0x40000000 / 0x80000000 = 50.00%
148header:
149  br label %body
150
151body:
152  %cond2 = icmp eq i32 %b, 42
153  br i1 %cond2, label %header, label %exit
154; CHECK: edge body -> header probability is 0x7fbe1203 / 0x80000000 = 99.80% [HOT edge]
155; CHECK: edge body -> exit probability is 0x0041edfd / 0x80000000 = 0.20%
156exit:
157  call void @coldfunc()
158  ret i32 %b
159}
160
161declare i32 @regular_function(i32 %i)
162
163define i32 @test_cold_call_sites_with_prof(i32 %a, i32 %b, i1 %flag, i1 %flag2) {
164; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites_with_prof'
165entry:
166  br i1 %flag, label %then, label %else
167; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
168; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
169
170then:
171  br i1 %flag2, label %then2, label %else2, !prof !3
172; CHECK: edge then -> then2 probability is 0x7ebb907a / 0x80000000 = 99.01% [HOT edge]
173; CHECK: edge then -> else2 probability is 0x01446f86 / 0x80000000 = 0.99%
174
175then2:
176  br label %join
177; CHECK: edge then2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
178
179else2:
180  br label %join
181; CHECK: edge else2 -> join probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
182
183join:
184  %joinresult = phi i32 [ %a, %then2 ], [ %b, %else2 ]
185  call void @coldfunc()
186  br label %exit
187; CHECK: edge join -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
188
189else:
190  br label %exit
191; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
192
193exit:
194  %result = phi i32 [ %joinresult, %join ], [ %b, %else ]
195  ret i32 %result
196}
197
198!3 = !{!"branch_weights", i32 100, i32 1}
199
200define i32 @test_cold_call_sites(i32* %a) {
201; Test that edges to blocks post-dominated by cold call sites
202; are marked as not expected to be taken.
203; TODO(dnovillo) The calls to regular_function should not be merged, but
204; they are currently being merged. Convert this into a code generation test
205; after that is fixed.
206
207; CHECK: Printing analysis {{.*}} for function 'test_cold_call_sites'
208; CHECK: edge entry -> then probability is 0x078780e3 / 0x80000000 = 5.88%
209; CHECK: edge entry -> else probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
210
211entry:
212  %gep1 = getelementptr i32, i32* %a, i32 1
213  %val1 = load i32, i32* %gep1
214  %cond1 = icmp ugt i32 %val1, 1
215  br i1 %cond1, label %then, label %else
216
217then:
218  ; This function is not declared cold, but this call site is.
219  %val4 = call i32 @regular_function(i32 %val1) cold
220  br label %exit
221
222else:
223  %gep2 = getelementptr i32, i32* %a, i32 2
224  %val2 = load i32, i32* %gep2
225  %val3 = call i32 @regular_function(i32 %val2)
226  br label %exit
227
228exit:
229  %ret = phi i32 [ %val4, %then ], [ %val3, %else ]
230  ret i32 %ret
231}
232
233; CHECK-LABEL: test_invoke_code_callsite1
234define i32 @test_invoke_code_callsite1(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
235entry:
236  br i1 %c, label %if.then, label %if.end
237; Edge "entry->if.end" should have higher probability based on the cold call
238; heuristic which treat %if.then as a cold block because the normal destination
239; of the invoke instruction in %if.then is post-dominated by ColdFunc().
240; CHECK:  edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
241; CHECK:  edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
242
243if.then:
244  invoke i32 @InvokeCall()
245          to label %invoke.cont unwind label %lpad
246; CHECK:  edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
247; CHECK:  edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
248
249invoke.cont:
250  call void @ColdFunc() #0
251  br label %if.end
252
253lpad:
254  %ll = landingpad { i8*, i32 }
255          cleanup
256  br label %if.end
257
258if.end:
259  ret i32 0
260}
261
262; CHECK-LABEL: test_invoke_code_callsite2
263define i32 @test_invoke_code_callsite2(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
264entry:
265  br i1 %c, label %if.then, label %if.end
266
267; CHECK:  edge entry -> if.then probability is 0x40000000 / 0x80000000 = 50.00%
268; CHECK:  edge entry -> if.end probability is 0x40000000 / 0x80000000 = 50.00%
269if.then:
270  invoke i32 @InvokeCall()
271          to label %invoke.cont unwind label %lpad
272; The cold call heuristic should not kick in when the cold callsite is in EH path.
273; CHECK: edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
274; CHECK: edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
275
276invoke.cont:
277  br label %if.end
278
279lpad:
280  %ll = landingpad { i8*, i32 }
281          cleanup
282  call void @ColdFunc() #0
283  br label %if.end
284
285if.end:
286  ret i32 0
287}
288
289; CHECK-LABEL: test_invoke_code_callsite3
290define i32 @test_invoke_code_callsite3(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
291entry:
292  br i1 %c, label %if.then, label %if.end
293; CHECK: edge entry -> if.then probability is 0x078780e3 / 0x80000000 = 5.88%
294; CHECK: edge entry -> if.end probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
295
296if.then:
297  invoke i32 @InvokeCall()
298          to label %invoke.cont unwind label %lpad
299; Regardless of cold calls, edge weights from a invoke instruction should be
300; determined by the invoke heuristic.
301; CHECK: edge if.then -> invoke.cont probability is 0x7fff8000 / 0x80000000 = 100.00% [HOT edge]
302; CHECK: edge if.then -> lpad probability is 0x00008000 / 0x80000000 = 0.00%
303
304invoke.cont:
305  call void @ColdFunc() #0
306  br label %if.end
307
308lpad:
309  %ll = landingpad { i8*, i32 }
310          cleanup
311  call void @ColdFunc() #0
312  br label %if.end
313
314if.end:
315  ret i32 0
316}
317
318; CHECK-LABEL: test_invoke_code_profiled
319define void @test_invoke_code_profiled(i1 %c) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
320entry:
321; CHECK: edge entry -> invoke.to0 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
322; CHECK: edge entry -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
323  invoke i32 @InvokeCall() to label %invoke.to0 unwind label %lpad
324
325invoke.to0:
326; CHECK: edge invoke.to0 -> invoke.to1 probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
327; CHECK: edge invoke.to0 -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
328  invoke i32 @InvokeCall() to label %invoke.to1 unwind label %lpad,
329     !prof !{!"branch_weights", i32 444}
330
331invoke.to1:
332; CHECK: invoke.to1 -> invoke.to2 probability is 0x55555555 / 0x80000000 = 66.67%
333; CHECK: invoke.to1 -> lpad probability is 0x2aaaaaab / 0x80000000 = 33.33%
334  invoke i32 @InvokeCall() to label %invoke.to2 unwind label %lpad,
335     !prof !{!"branch_weights", i32 222, i32 111}
336  ret void
337
338invoke.to2:
339  ret void
340
341lpad:
342  %ll = landingpad { i8*, i32 }
343          cleanup
344  ret void
345}
346
347declare i32 @__gxx_personality_v0(...)
348declare void  @ColdFunc()
349declare i32 @InvokeCall()
350
351attributes #0 = { cold }
352
353
354define i32 @zero1(i32 %i, i32 %a, i32 %b) {
355; CHECK: Printing analysis {{.*}} for function 'zero1'
356entry:
357  %cond = icmp eq i32 %i, 0
358  br i1 %cond, label %then, label %else
359; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
360; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
361
362then:
363  br label %exit
364
365else:
366  br label %exit
367
368exit:
369  %result = phi i32 [ %a, %then ], [ %b, %else ]
370  ret i32 %result
371}
372
373define i32 @zero2(i32 %i, i32 %a, i32 %b) {
374; CHECK: Printing analysis {{.*}} for function 'zero2'
375entry:
376  %cond = icmp ne i32 %i, -1
377  br i1 %cond, label %then, label %else
378; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
379; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
380
381then:
382  br label %exit
383
384else:
385  br label %exit
386
387exit:
388  %result = phi i32 [ %a, %then ], [ %b, %else ]
389  ret i32 %result
390}
391
392define i32 @zero3(i32 %i, i32 %a, i32 %b) {
393; CHECK: Printing analysis {{.*}} for function 'zero3'
394entry:
395; AND'ing with a single bit bitmask essentially leads to a bool comparison,
396; meaning we don't have probability information.
397  %and = and i32 %i, 2
398  %tobool = icmp eq i32 %and, 0
399  br i1 %tobool, label %then, label %else
400; CHECK: edge entry -> then probability is 0x40000000 / 0x80000000 = 50.00%
401; CHECK: edge entry -> else probability is 0x40000000 / 0x80000000 = 50.00%
402
403then:
404; AND'ing with other bitmask might be something else, so we still assume the
405; usual probabilities.
406  %and2 = and i32 %i, 5
407  %tobool2 = icmp eq i32 %and2, 0
408  br i1 %tobool2, label %else, label %exit
409; CHECK: edge then -> else probability is 0x30000000 / 0x80000000 = 37.50%
410; CHECK: edge then -> exit probability is 0x50000000 / 0x80000000 = 62.50%
411
412else:
413  br label %exit
414
415exit:
416  %result = phi i32 [ %a, %then ], [ %b, %else ]
417  ret i32 %result
418}
419
420define i32 @test_unreachable_with_prof_greater(i32 %a, i32 %b) {
421; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_greater'
422entry:
423  %cond = icmp eq i32 %a, 42
424  br i1 %cond, label %exit, label %unr, !prof !4
425
426; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
427; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
428
429unr:
430  unreachable
431
432exit:
433  ret i32 %b
434}
435
436!4 = !{!"branch_weights", i32 0, i32 1}
437
438define i32 @test_unreachable_with_prof_equal(i32 %a, i32 %b) {
439; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_equal'
440entry:
441  %cond = icmp eq i32 %a, 42
442  br i1 %cond, label %exit, label %unr, !prof !5
443
444; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
445; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
446
447unr:
448  unreachable
449
450exit:
451  ret i32 %b
452}
453
454!5 = !{!"branch_weights", i32 2147483647, i32 1}
455
456define i32 @test_unreachable_with_prof_zero(i32 %a, i32 %b) {
457; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_zero'
458entry:
459  %cond = icmp eq i32 %a, 42
460  br i1 %cond, label %exit, label %unr, !prof !6
461
462; CHECK:  edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
463; CHECK:  edge entry -> unr probability is 0x00000001 / 0x80000000 = 0.00%
464
465unr:
466  unreachable
467
468exit:
469  ret i32 %b
470}
471
472!6 = !{!"branch_weights", i32 0, i32 0}
473
474define i32 @test_unreachable_with_prof_less(i32 %a, i32 %b) {
475; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_prof_less'
476entry:
477  %cond = icmp eq i32 %a, 42
478  br i1 %cond, label %exit, label %unr, !prof !7
479
480; CHECK:  edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
481; CHECK:  edge entry -> unr probability is 0x00000000 / 0x80000000 = 0.00%
482
483unr:
484  unreachable
485
486exit:
487  ret i32 %b
488}
489
490!7 = !{!"branch_weights", i32 1, i32 0}
491
492define i32 @test_unreachable_with_switch_prof1(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
493; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof1'
494entry:
495  switch i32 %i, label %case_a [ i32 1, label %case_b
496                                 i32 2, label %case_c
497                                 i32 3, label %case_d
498                                 i32 4, label %case_e ], !prof !8
499; Reachable probabilities keep their relation: 4/64/4/4 = 5.26% / 84.21% / 5.26% / 5.26%.
500; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00%
501; CHECK: edge entry -> case_b probability is 0x06bca1af / 0x80000000 = 5.26%
502; CHECK: edge entry -> case_c probability is 0x6bca1af3 / 0x80000000 = 84.21% [HOT edge]
503; CHECK: edge entry -> case_d probability is 0x06bca1af / 0x80000000 = 5.26%
504; CHECK: edge entry -> case_e probability is 0x06bca1af / 0x80000000 = 5.26%
505
506case_a:
507  unreachable
508
509case_b:
510  br label %exit
511; CHECK: edge case_b -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
512
513case_c:
514  br label %exit
515; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
516
517case_d:
518  br label %exit
519; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
520
521case_e:
522  br label %exit
523; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
524
525exit:
526  %result = phi i32 [ %b, %case_b ],
527                    [ %c, %case_c ],
528                    [ %d, %case_d ],
529                    [ %e, %case_e ]
530  ret i32 %result
531}
532
533!8 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
534
535define i32 @test_unreachable_with_switch_prof2(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
536; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof2'
537entry:
538  switch i32 %i, label %case_a [ i32 1, label %case_b
539                                 i32 2, label %case_c
540                                 i32 3, label %case_d
541                                 i32 4, label %case_e ], !prof !9
542; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%.
543; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00%
544; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00%
545; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge]
546; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56%
547; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56%
548
549
550case_a:
551  unreachable
552
553case_b:
554  unreachable
555
556case_c:
557  br label %exit
558; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
559
560case_d:
561  br label %exit
562; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
563
564case_e:
565  br label %exit
566; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
567
568exit:
569  %result = phi i32 [ %c, %case_c ],
570                    [ %d, %case_d ],
571                    [ %e, %case_e ]
572  ret i32 %result
573}
574
575!9 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
576
577define i32 @test_unreachable_with_switch_prof3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
578; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof3'
579entry:
580  switch i32 %i, label %case_a [ i32 1, label %case_b
581                                 i32 2, label %case_c
582                                 i32 3, label %case_d
583                                 i32 4, label %case_e ], !prof !10
584; Reachable probabilities keep their relation: 64/4/4 = 88.89% / 5.56% / 5.56%.
585; CHECK: edge entry -> case_a probability is 0x00000000 / 0x80000000 = 0.00%
586; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00%
587; CHECK: edge entry -> case_c probability is 0x71c71c71 / 0x80000000 = 88.89% [HOT edge]
588; CHECK: edge entry -> case_d probability is 0x071c71c7 / 0x80000000 = 5.56%
589; CHECK: edge entry -> case_e probability is 0x071c71c7 / 0x80000000 = 5.56%
590
591case_a:
592  unreachable
593
594case_b:
595  unreachable
596
597case_c:
598  br label %exit
599; CHECK: edge case_c -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
600
601case_d:
602  br label %exit
603; CHECK: edge case_d -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
604
605case_e:
606  br label %exit
607; CHECK: edge case_e -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
608
609exit:
610  %result = phi i32 [ %c, %case_c ],
611                    [ %d, %case_d ],
612                    [ %e, %case_e ]
613  ret i32 %result
614}
615
616!10 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}
617
618define i32 @test_unreachable_with_switch_prof4(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
619; CHECK: Printing analysis {{.*}} for function 'test_unreachable_with_switch_prof4'
620entry:
621  switch i32 %i, label %case_a [ i32 1, label %case_b
622                                 i32 2, label %case_c
623                                 i32 3, label %case_d
624                                 i32 4, label %case_e ], !prof !11
625; CHECK: edge entry -> case_a probability is 0x1999999a / 0x80000000 = 20.00%
626; CHECK: edge entry -> case_b probability is 0x1999999a / 0x80000000 = 20.00%
627; CHECK: edge entry -> case_c probability is 0x1999999a / 0x80000000 = 20.00%
628; CHECK: edge entry -> case_d probability is 0x1999999a / 0x80000000 = 20.00%
629; CHECK: edge entry -> case_e probability is 0x1999999a / 0x80000000 = 20.00%
630
631case_a:
632  unreachable
633
634case_b:
635  unreachable
636
637case_c:
638  unreachable
639
640case_d:
641  unreachable
642
643case_e:
644  unreachable
645
646}
647
648!11 = !{!"branch_weights", i32 0, i32 4, i32 64, i32 4, i32 4}
649