[PATCH] D141579: [PGO] incorrect classof in InstrProfIncrementInst

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 07:03:30 PST 2023


tejohnson added a comment.

Thanks for adding a test, couple questions below, but generally lgtm.

In D141579#4057747 <https://reviews.llvm.org/D141579#4057747>, @KuiChou wrote:

> In D141579#4047994 <https://reviews.llvm.org/D141579#4047994>, @ellis wrote:
>
>> Ah, I see the `dyn_cast` you are talking about is here <https://github.com/llvm/llvm-project/blob/9f1bb307da6fec6fc8123bdec79ecec28fced874/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp#L548-L549>. I think this is only a problem if `InstrProfIncrementInstStep` is the only InstrProf instruction in a function **and** it has an `llvm.instrprof.value.profile` instruction, which explains why we didn't catch this bug for so long. In that case, the later call to `getOrCreateRegionCounters()` will be skipped and, according to the comment, this is required for value profiling. Is that what you observed? If so it should be easy to add a small test case, probably similar to `llvm/test/Instrumentation/InstrProfiling/early-exit.ll`, but this could be followed up in another patch. Thanks for fixing!
>
> Yes. But even if `InstrProfIncrementInstStep` is the only InstrProf instruction in a function, `getOrCreateRegionCounters` will still be called through `InstrProfiling::run` -> `lowerIntrinsics` -> `lowerIncrement` -> `getCounterAddress` -> `getOrCreateRegionCounters`. So, to reproduce this problem, we should satisfy two conditions:
>
> 1. `InstrProfIncrementInstStep` is the only InstrProf instruction in a function **and** it has `InstrProfValueProfileInst` instruction

I assume this should be "is the only InstrProfIncrement instruction" (since there is another InstrProf instruction in the function (InstrProfValueProfileInst)?

> 2. `InstrProfValueProfileInst` must be **in front of** `InstrProfIncrementInstStep` instruction
>
> PGO will always generate an `InstrProfIncrementInst` instruction in the front of a function so normally, this bug cannot happen

Out of curiosity, how was this encountered?



================
Comment at: llvm/test/Instrumentation/InstrProfiling/before-value-profile-lowering.ll:1
+; Check that profile data variable is genereated before value profile lowering
+
----------------
s/genereated/generated/

Also, suggest expanding the comment to clarify the exact scenario being tested, e.g. something like: ", when the only instrprof increment is a step instruction following a value profile instruction."


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141579/new/

https://reviews.llvm.org/D141579



More information about the llvm-commits mailing list