1 ; Note: Verify bfi counter after loading the profile.
2 ; RUN: llvm-profdata merge %S/Inputs/bfi_verification.proftext -o %t.profdata
3 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-verify-bfi-ratio=2 -pgo-verify-bfi=true -pgo-fix-entry-count=false -pass-remarks-analysis=pgo 2>&1 | FileCheck %s --check-prefix=THRESHOLD-CHECK
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S -pgo-verify-hot-bfi=true -pgo-fix-entry-count=false -pass-remarks-analysis=pgo 2>&1 | FileCheck %s --check-prefix=HOTONLY-CHECK
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
9 %struct.basket = type { ptr, i64, i64 }
10 %struct.arc = type { i64, ptr, ptr, i32, ptr, ptr, i64, i64 }
11 %struct.node = type { i64, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32 }
13 @perm = internal unnamed_addr global [351 x ptr] zeroinitializer, align 16
15 define dso_local void @sort_basket(i64 %min, i64 %max) {
17 %add = add nsw i64 %min, %max
18 %div = sdiv i64 %add, 2
19 %arrayidx = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %div
20 %0 = load ptr, ptr %arrayidx, align 8
21 %abs_cost = getelementptr inbounds %struct.basket, ptr %0, i64 0, i32 2
22 %1 = load i64, ptr %abs_cost, align 8
26 %r.0 = phi i64 [ %max, %entry ], [ %r.2, %if.end ]
27 %l.0 = phi i64 [ %min, %entry ], [ %l.2, %if.end ]
31 %l.1 = phi i64 [ %l.0, %do.body ], [ %inc, %while.body ]
32 %arrayidx1 = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %l.1
33 %2 = load ptr, ptr %arrayidx1, align 8
34 %abs_cost2 = getelementptr inbounds %struct.basket, ptr %2, i64 0, i32 2
35 %3 = load i64, ptr %abs_cost2, align 8
36 %cmp = icmp sgt i64 %3, %1
37 br i1 %cmp, label %while.body, label %while.cond3
40 %inc = add nsw i64 %l.1, 1
44 %r.1 = phi i64 [ %r.0, %while.cond ], [ %dec, %while.body7 ]
45 %arrayidx4 = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %r.1
46 %4 = load ptr, ptr %arrayidx4, align 8
47 %abs_cost5 = getelementptr inbounds %struct.basket, ptr %4, i64 0, i32 2
48 %5 = load i64, ptr %abs_cost5, align 8
49 %cmp6 = icmp sgt i64 %1, %5
50 br i1 %cmp6, label %while.body7, label %while.end8
53 %dec = add nsw i64 %r.1, -1
57 %cmp9 = icmp slt i64 %l.1, %r.1
58 br i1 %cmp9, label %if.then, label %if.end
61 %6 = load i64, ptr %arrayidx1, align 8
62 store ptr %4, ptr %arrayidx1, align 8
63 store i64 %6, ptr %arrayidx4, align 8
67 %cmp14 = icmp sgt i64 %l.1, %r.1
68 %not.cmp14 = xor i1 %cmp14, true
69 %7 = zext i1 %not.cmp14 to i64
70 %r.2 = sub i64 %r.1, %7
71 %not.cmp1457 = xor i1 %cmp14, true
72 %inc16 = zext i1 %not.cmp1457 to i64
73 %l.2 = add nsw i64 %l.1, %inc16
74 %cmp19 = icmp sgt i64 %l.2, %r.2
75 br i1 %cmp19, label %do.end, label %do.body
78 %cmp20 = icmp sgt i64 %r.2, %min
79 br i1 %cmp20, label %if.then21, label %if.end22
82 call void @sort_basket(i64 %min, i64 %r.2)
86 %cmp23 = icmp slt i64 %l.2, %max
87 %cmp24 = icmp slt i64 %l.2, 51
88 %or.cond = and i1 %cmp23, %cmp24
89 br i1 %or.cond, label %if.then25, label %if.end26
92 call void @sort_basket(i64 %l.2, i64 %max)
98 ; THRESHOLD-CHECK: remark: <unknown>:0:0: BB while.body7 Count=77 BFI_Count=1845778
99 ; THRESHOLD-CHECK: remark: <unknown>:0:0: BB if.then21 Count=2 BFI_Count=621
100 ; THRESHOLD-CHECK: remark: <unknown>:0:0: In Func sort_basket: Num_of_BB=14, Num_of_non_zerovalue_BB=14, Num_of_mis_matching_BB=2
101 ; TODO: I am not sure how to reproduce the situation of hot/cold switching: We currently choose
102 ; factors in `convertFloatingToInteger` so precision is kept at high end, so hot blocks should stay hot.
103 ; HOTONLY-CHECK: {{.*}}