xref: /llvm-project/llvm/test/Transforms/PGOProfile/counter_promo_with_bias.ll (revision a5128542495d04e20db0828bceaae69c39e72c6d)
1; RUN: opt < %s -passes=instrprof -runtime-counter-relocation -do-counter-promotion=true -S | FileCheck %s
2
3target triple = "x86_64-unknown-linux-gnu"
4
5@__profn_foo = private constant [3 x i8] c"foo"
6
7define void @foo(i1 %c) {
8entry:
9; CHECK: %[[BIAS:.+]] = load i64, ptr @__llvm_profile_counter_bias
10  br label %while.cond
11
12while.cond:                                       ; preds = %land.rhs, %while.cond.preheader
13; CHECK: %[[COUNT:[a-z0-9.]+]] = phi i64 [ %[[LAND_COUNT:[0-9]+]], %land.rhs ], [ 0, %entry ]
14  br i1 %c, label %while.cond.cleanup_crit_edge, label %land.rhs
15
16while.cond.cleanup_crit_edge:                     ; preds = %while.cond
17; CHECK: %[[COUNTER_PTR:[0-9]+]] = add i64 ptrtoint (ptr @__profc_foo to i64), %[[BIAS]]
18; CHECK: %[[COUNTER_ADDR:[0-9]+]] = inttoptr i64 %[[COUNTER_PTR]] to ptr
19; CHECK: %[[COUNTER_PROMO:[a-z0-9.]+]] = load i64, ptr %[[COUNTER_ADDR]]
20; CHECK: %[[VALUE:[0-9]+]] = add i64 %[[COUNTER_PROMO]], %[[COUNT]]
21; CHECK: store i64 %[[VALUE]], ptr %[[COUNTER_ADDR]]
22  br label %cleanup
23
24land.rhs:                                         ; preds = %while.cond
25  call void @llvm.instrprof.increment(ptr @__profn_foo, i64 0, i32 1, i32 0)
26; CHECK: %[[LAND_COUNT]] = add i64 %[[COUNT]], 1
27  br label %while.cond
28
29cleanup:                                          ; preds = %while.cond.cleanup_crit_edge
30  ret void
31}
32
33declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
34