[llvm] [PGO] Add `llvm.loop.estimated_trip_count` metadata (PR #148758)
Joel E. Denny via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 31 14:08:16 PDT 2025
jdenny-ornl wrote:
> Less of an issue than the compile time regression, but this also introduced a layering violation between IR and TransformUtils. ~every file in lib/Transforms/Utils/ uses llvm/IR/*.h, and this commit added the reverse dependency as now llvm/lib/IR/Verifier.cpp includes llvm/Transforms/Utils/LoopUtils.h.
That just enables the verifier and utils to share `LLVMLoopEstimatedTripCount = "llvm.loop.estimated_trip_count"`. What's the right way to do that?
> Could this be enabled behind a flag? IIRC there are a few changes needed here, besides this one; after which presumably we could try it out on some benchmarks.
If I understood correctly, the problems @nikic pointed out are all related to the new pass. Even with this PR, `getLoopEstimatedTripCount` still estimates trip counts from branch weights when the metadata is missing, so my patches to fix BFI issues do not need the pass. For my purposes then, yes, the pass can go behind a flag so that the pass can be investigated as an orthogonal issue.
> I'm not super clear on what the benefits of this approach with an early inference pass are. I like this _conceptually_, but if in practice we can usually only infer the estimated trip counts after loop rotation, is the early pass really useful?
@mtrofin Would you comment on this point?
> It's probably worth pointing out that just the presence of loop metadata impacts optimization behavior (in an attempt to preserve the metadata), so inserting dummy metadata for all loops will have secondary effects.
One possibility is for the pass to add the new metadata only to loops that have branch weights. That way, you would only pay for it when you are doing PGO-like work. The PR currently adds the metadata without a value in that case.
https://github.com/llvm/llvm-project/pull/148758
More information about the llvm-commits
mailing list