[llvm] [InstrProf] Support conditional counter updates (PR #102542)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 06:13:37 PDT 2024


================
@@ -1213,6 +1218,18 @@ Value *InstrLowerer::getBitmapAddress(InstrProfMCDCTVBitmapUpdate *I) {
 void InstrLowerer::lowerCover(InstrProfCoverInst *CoverInstruction) {
   auto *Addr = getCounterAddress(CoverInstruction);
   IRBuilder<> Builder(CoverInstruction);
+  if (ConditionalCounterUpdate) {
+    Instruction *SplitBefore = CoverInstruction->getNextNode();
+    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");
----------------
jmmartinez wrote:

No real advantage. It's just a nitpick.

I find `CreateIsNotNull` expresses the intent of the code better:
* the name is more meaningful since this the generated code checks if the counter "is not zero" (even the name of the instruction is `"pgocount.ifnonzero"`).
* and it's less verbose (no need to read the creation of the constant and the type)

If you think ICmpNE is more suitable, it's ok for me. But I think these more specific abstractions are there for a reason.

https://github.com/llvm/llvm-project/pull/102542


More information about the llvm-commits mailing list