[llvm] [InstrProf] Support conditional counter updates for integer counters (PR #109222)
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 23:32:21 PDT 2024
================
@@ -1263,8 +1263,21 @@ void InstrLowerer::lowerIncrement(InstrProfIncrementInst *Inc) {
MaybeAlign(), AtomicOrdering::Monotonic);
} else {
Value *IncStep = Inc->getStep();
- Value *Load = Builder.CreateLoad(IncStep->getType(), Addr, "pgocount");
- auto *Count = Builder.CreateAdd(Load, Inc->getStep());
+ auto *CtrTy = IncStep->getType();
+ Value *Load = Builder.CreateLoad(CtrTy, Addr, "pgocount");
+ Value *Count;
+
+ if (ConditionalCounterUpdate) {
+ Instruction *SplitBefore = Inc->getNextNode();
+ Value *Cmp = Builder.CreateIsNull(Load, "pgocount.ifzero");
+ Instruction *ThenBranch =
+ SplitBlockAndInsertIfThen(Cmp, SplitBefore, false);
+ Builder.SetInsertPoint(ThenBranch);
+ Count = ConstantInt::get(CtrTy, 1);
+ } else {
+ Count = Builder.CreateAdd(Load, Inc->getStep());
+ }
----------------
petrhosek wrote:
Could we use increment even for conditional counter updates for consistency?
```suggestion
}
Count = Builder.CreateAdd(Load, Inc->getStep());
```
https://github.com/llvm/llvm-project/pull/109222
More information about the llvm-commits
mailing list