xref: /llvm-project/llvm/test/Transforms/PGOProfile/bfi_verification.ll (revision e3cf80c5c1fe55efd8216575ccadea0ab087e79c)
154e03d03SRong Xu; Note: Verify bfi counter after loading the profile.
254e03d03SRong Xu; RUN: llvm-profdata merge %S/Inputs/bfi_verification.proftext -o %t.profdata
3b5d884a3SFangrui Song; 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
4b5d884a3SFangrui Song; 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
554e03d03SRong Xu
654e03d03SRong Xutarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
754e03d03SRong Xutarget triple = "x86_64-unknown-linux-gnu"
854e03d03SRong Xu
99ff36df5SFangrui Song%struct.basket = type { ptr, i64, i64 }
109ff36df5SFangrui Song%struct.arc = type { i64, ptr, ptr, i32, ptr, ptr, i64, i64 }
119ff36df5SFangrui Song%struct.node = type { i64, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i32, i32 }
1254e03d03SRong Xu
139ff36df5SFangrui Song@perm = internal unnamed_addr global [351 x ptr] zeroinitializer, align 16
1454e03d03SRong Xu
1554e03d03SRong Xudefine dso_local void @sort_basket(i64 %min, i64 %max) {
1654e03d03SRong Xuentry:
1754e03d03SRong Xu  %add = add nsw i64 %min, %max
1854e03d03SRong Xu  %div = sdiv i64 %add, 2
199ff36df5SFangrui Song  %arrayidx = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %div
209ff36df5SFangrui Song  %0 = load ptr, ptr %arrayidx, align 8
219ff36df5SFangrui Song  %abs_cost = getelementptr inbounds %struct.basket, ptr %0, i64 0, i32 2
229ff36df5SFangrui Song  %1 = load i64, ptr %abs_cost, align 8
2354e03d03SRong Xu  br label %do.body
2454e03d03SRong Xu
2554e03d03SRong Xudo.body:
2654e03d03SRong Xu  %r.0 = phi i64 [ %max, %entry ], [ %r.2, %if.end ]
2754e03d03SRong Xu  %l.0 = phi i64 [ %min, %entry ], [ %l.2, %if.end ]
2854e03d03SRong Xu  br label %while.cond
2954e03d03SRong Xu
3054e03d03SRong Xuwhile.cond:
3154e03d03SRong Xu  %l.1 = phi i64 [ %l.0, %do.body ], [ %inc, %while.body ]
329ff36df5SFangrui Song  %arrayidx1 = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %l.1
339ff36df5SFangrui Song  %2 = load ptr, ptr %arrayidx1, align 8
349ff36df5SFangrui Song  %abs_cost2 = getelementptr inbounds %struct.basket, ptr %2, i64 0, i32 2
359ff36df5SFangrui Song  %3 = load i64, ptr %abs_cost2, align 8
3654e03d03SRong Xu  %cmp = icmp sgt i64 %3, %1
3754e03d03SRong Xu  br i1 %cmp, label %while.body, label %while.cond3
3854e03d03SRong Xu
3954e03d03SRong Xuwhile.body:
4054e03d03SRong Xu  %inc = add nsw i64 %l.1, 1
4154e03d03SRong Xu  br label %while.cond
4254e03d03SRong Xu
4354e03d03SRong Xuwhile.cond3:
4454e03d03SRong Xu  %r.1 = phi i64 [ %r.0, %while.cond ], [ %dec, %while.body7 ]
459ff36df5SFangrui Song  %arrayidx4 = getelementptr inbounds [351 x ptr], ptr @perm, i64 0, i64 %r.1
469ff36df5SFangrui Song  %4 = load ptr, ptr %arrayidx4, align 8
479ff36df5SFangrui Song  %abs_cost5 = getelementptr inbounds %struct.basket, ptr %4, i64 0, i32 2
489ff36df5SFangrui Song  %5 = load i64, ptr %abs_cost5, align 8
4954e03d03SRong Xu  %cmp6 = icmp sgt i64 %1, %5
5054e03d03SRong Xu  br i1 %cmp6, label %while.body7, label %while.end8
5154e03d03SRong Xu
5254e03d03SRong Xuwhile.body7:
5354e03d03SRong Xu  %dec = add nsw i64 %r.1, -1
5454e03d03SRong Xu  br label %while.cond3
5554e03d03SRong Xu
5654e03d03SRong Xuwhile.end8:
5754e03d03SRong Xu  %cmp9 = icmp slt i64 %l.1, %r.1
5854e03d03SRong Xu  br i1 %cmp9, label %if.then, label %if.end
5954e03d03SRong Xu
6054e03d03SRong Xuif.then:
619ff36df5SFangrui Song  %6 = load i64, ptr %arrayidx1, align 8
629ff36df5SFangrui Song  store ptr %4, ptr %arrayidx1, align 8
639ff36df5SFangrui Song  store i64 %6, ptr %arrayidx4, align 8
6454e03d03SRong Xu  br label %if.end
6554e03d03SRong Xu
6654e03d03SRong Xuif.end:
6754e03d03SRong Xu  %cmp14 = icmp sgt i64 %l.1, %r.1
6854e03d03SRong Xu  %not.cmp14 = xor i1 %cmp14, true
699ff36df5SFangrui Song  %7 = zext i1 %not.cmp14 to i64
709ff36df5SFangrui Song  %r.2 = sub i64 %r.1, %7
7154e03d03SRong Xu  %not.cmp1457 = xor i1 %cmp14, true
7254e03d03SRong Xu  %inc16 = zext i1 %not.cmp1457 to i64
7354e03d03SRong Xu  %l.2 = add nsw i64 %l.1, %inc16
7454e03d03SRong Xu  %cmp19 = icmp sgt i64 %l.2, %r.2
7554e03d03SRong Xu  br i1 %cmp19, label %do.end, label %do.body
7654e03d03SRong Xu
7754e03d03SRong Xudo.end:
7854e03d03SRong Xu  %cmp20 = icmp sgt i64 %r.2, %min
7954e03d03SRong Xu  br i1 %cmp20, label %if.then21, label %if.end22
8054e03d03SRong Xu
8154e03d03SRong Xuif.then21:
8254e03d03SRong Xu  call void @sort_basket(i64 %min, i64 %r.2)
8354e03d03SRong Xu  br label %if.end22
8454e03d03SRong Xu
8554e03d03SRong Xuif.end22:
8654e03d03SRong Xu  %cmp23 = icmp slt i64 %l.2, %max
8754e03d03SRong Xu  %cmp24 = icmp slt i64 %l.2, 51
8854e03d03SRong Xu  %or.cond = and i1 %cmp23, %cmp24
8954e03d03SRong Xu  br i1 %or.cond, label %if.then25, label %if.end26
9054e03d03SRong Xu
9154e03d03SRong Xuif.then25:
9254e03d03SRong Xu  call void @sort_basket(i64 %l.2, i64 %max)
9354e03d03SRong Xu  br label %if.end26
9454e03d03SRong Xu
9554e03d03SRong Xuif.end26:
9654e03d03SRong Xu  ret void
9754e03d03SRong Xu}
98*e3cf80c5SMatthias Braun; THRESHOLD-CHECK: remark: <unknown>:0:0: BB while.body7 Count=77 BFI_Count=1845778
99*e3cf80c5SMatthias Braun; THRESHOLD-CHECK: remark: <unknown>:0:0: BB if.then21 Count=2 BFI_Count=621
100*e3cf80c5SMatthias Braun; 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*e3cf80c5SMatthias Braun; TODO: I am not sure how to reproduce the situation of hot/cold switching: We currently choose
102*e3cf80c5SMatthias Braun; factors in `convertFloatingToInteger` so precision is kept at high end, so hot blocks should stay hot.
103*e3cf80c5SMatthias Braun; HOTONLY-CHECK: {{.*}}
104