[llvm] [PGO] Add llvm.loop.estimated_trip_count metadata (PR #152775)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 17 08:00:55 PDT 2025


nikic wrote:

@jdenny-ornl Thanks for looking into it. So this is indeed related to the fact that merely adding loop metadata can change optimization behavior. A likely culprit for this is this hack: https://github.com/llvm/llvm-project/blob/65ffa53cb70909be4dbedacd9de9de0725161592/llvm/lib/Transforms/Utils/Local.cpp#L1200

With that in mind, I don't think we should be doing early attachment of this metadata unless this issue can be fixed (as the comment indicates, by introducing block metadata).

Adding it lazily can also cause issues, but I'm hoping it would be to a lesser degree than adding it to every single loop. We should probably look out for the case where the latch is part of two loops though, so we don't mistakenly assign the same trip count to both an inner and an outer loop.

> Do you think we should remove the pass or just disable it by default, as was previously suggested? I am leery of the latter because I am afraid it will just end up being unused code, unless someone else commits to continuing to investigate it.

I agree. Based on past experience, either a pass needs to be enabled right away, or it will never get enabled.

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


More information about the llvm-commits mailing list