diff options
author | Joel E. Denny <jdenny.ornl@gmail.com> | 2025-07-31 12:28:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-31 12:28:25 -0400 |
commit | f7b65011de519b1bd987892475db61f99dde44ce (patch) | |
tree | 5550563d8ac0f12271a6cb7d948ba559f4301b78 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 3e579d93ab50952628a51bda05f3a39f6a5a631c (diff) | |
download | llvm-f7b65011de519b1bd987892475db61f99dde44ce.zip llvm-f7b65011de519b1bd987892475db61f99dde44ce.tar.gz llvm-f7b65011de519b1bd987892475db61f99dde44ce.tar.bz2 |
[PGO] Add `llvm.loop.estimated_trip_count` metadata (#148758)
This patch implements the `llvm.loop.estimated_trip_count` metadata
discussed in [[RFC] Fix Loop Transformations to Preserve Block
Frequencies](https://discourse.llvm.org/t/rfc-fix-loop-transformations-to-preserve-block-frequencies/85785).
As [suggested in the RFC
comments](https://discourse.llvm.org/t/rfc-fix-loop-transformations-to-preserve-block-frequencies/85785/4),
it adds the new metadata to all loops at the time of profile ingestion
and estimates each trip count from the loop's `branch_weights` metadata.
As [suggested in the PR #128785
review](https://github.com/llvm/llvm-project/pull/128785#discussion_r2151091036),
it does so via a new `PGOEstimateTripCountsPass` pass, which creates the
new metadata for each loop but omits the value if it cannot estimate a
trip count due to the loop's form.
An important observation not previously discussed is that
`PGOEstimateTripCountsPass` *often* cannot estimate a loop's trip count,
but later passes can sometimes transform the loop in a way that makes it
possible. Currently, such passes do not necessarily update the metadata,
but eventually that should be fixed. Until then, if the new metadata has
no value, `llvm::getLoopEstimatedTripCount` disregards it and tries
again to estimate the trip count from the loop's current
`branch_weights` metadata.
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
0 files changed, 0 insertions, 0 deletions