1 ; RUN: opt -S -jump-threading < %s | FileCheck %s
3 ; Check that based solely on static profile estimation we don't update the
4 ; branch-weight metadata. Even if the function has an entry frequency, a
5 ; completely cold part of the CFG may be statically estimated.
7 ; For example in the loop below, jump threading would update the weight of the
8 ; loop-exiting branch to 0, drastically inflating the frequency of the loop
9 ; (in the range of billions).
11 ; This is the CFG of the loop. There is no run-time profile info for edges
12 ; inside the loop, so branch and block frequencies are estimated as shown:
30 ; First we thread eq_1->check_2 to check_3. Frequencies are updated to remove
31 ; the frequency of eq_1 from check_2 and then the false edge leaving check_2
32 ; (changed frequencies are highlighted with * *):
50 ; Next we thread eq_1->check_3 and eq_2->check_3 to check_1 as new edges to
51 ; the loop latch. Frequencies are updated to remove the frequency of eq_1
52 ; and eq_3 from check_3 and then the false edge leaving check_3 (changed
53 ; frequencies are highlighted with * *):
65 ; | (loop exit) | (*0*)
71 ; As a result, the loop exit edge ends up with 0 frequency which in turn makes
72 ; the loop header to have maximum frequency.
76 define void @foo(i32 *%p, i32 %n) !prof !0 {
78 %enter_loop = icmp eq i32 %n, 0
79 br i1 %enter_loop, label %exit, label %check_1, !prof !1
80 ; CHECK: br i1 %enter_loop, label %exit, label %check_1, !prof !1
83 %v = load i32, i32* %p
84 %cond1 = icmp eq i32 %v, 1
85 br i1 %cond1, label %eq_1, label %check_2
87 ; CHECK: br i1 %cond1, label %check_2.thread, label %check_2{{$}}
92 ; Verify the new edge:
93 ; CHECK: check_2.thread:
94 ; CHECK-NEXT: call void @bar()
95 ; CHECK-NEXT: br label %latch
98 %cond2 = icmp eq i32 %v, 2
99 br i1 %cond2, label %eq_2, label %check_3
101 ; CHECK: br i1 %cond2, label %eq_2, label %check_3{{$}}
106 ; Verify the new edge:
108 ; CHECK-NEXT: call void @bar()
109 ; CHECK-NEXT: br label %latch
112 %condE = icmp eq i32 %v, 3
113 br i1 %condE, label %exit, label %latch
115 ; CHECK: br i1 %condE, label %exit, label %latch{{$}}
124 !0 = !{!"function_entry_count", i64 120}
125 ; CHECK-NOT: branch_weights
126 !1 = !{!"branch_weights", i32 119, i32 1}
127 ; CHECK: !1 = !{!"branch_weights", i32 119, i32 1}
128 ; CHECK-NOT: branch_weights