[llvm] [InstrProf] Support conditional counter updates (PR #102542)
Alan Zhao via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 15:02:03 PDT 2024
================
@@ -1213,8 +1213,20 @@ Value *InstrLowerer::getBitmapAddress(InstrProfMCDCTVBitmapUpdate *I) {
void InstrLowerer::lowerCover(InstrProfCoverInst *CoverInstruction) {
auto *Addr = getCounterAddress(CoverInstruction);
IRBuilder<> Builder(CoverInstruction);
- // We store zero to represent that this block is covered.
- Builder.CreateStore(Builder.getInt8(0), Addr);
+ if (ConditionalCounterUpdate) {
+ auto &Ctx = CoverInstruction->getParent()->getContext();
+ auto *Int8Ty = llvm::Type::getInt8Ty(Ctx);
+ Value *Load = Builder.CreateLoad(Int8Ty, Addr, "pgocount");
+ Value *Cmp = Builder.CreateICmpNE(Load, ConstantInt::get(Int8Ty, 0),
+ "pgocount.ifnonzero");
+ Value *Sel =
+ Builder.CreateSelect(Cmp, Builder.getInt8(0), Load, "pgocount.select");
----------------
alanzhao1 wrote:
I think this has to be a compare and branch instruction instead of a load.
When I tried using a select statement like what's being done here, the select ends up being optimized to an unconditional write, which defeats this feature.
Source: see my earlier post on Discourse: https://discourse.llvm.org/t/rfc-single-byte-counters-for-source-based-code-coverage/75685/12?u=ayzhao
https://github.com/llvm/llvm-project/pull/102542
More information about the llvm-commits
mailing list