diff options
author | Ramkumar Ramachandra <ramkumar.ramachandra@codasip.com> | 2025-03-05 18:19:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-05 18:19:39 +0000 |
commit | 03da079968845e1f1312d09ff4e2ecee1933552e (patch) | |
tree | 7f2a2f9beba367fe23343c6a3ee1465f297e4c85 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | db70d760829258b9687ecd0d7ea959256e028334 (diff) | |
download | llvm-03da079968845e1f1312d09ff4e2ecee1933552e.zip llvm-03da079968845e1f1312d09ff4e2ecee1933552e.tar.gz llvm-03da079968845e1f1312d09ff4e2ecee1933552e.tar.bz2 |
[LoopUtils] Saturate at INT_MAX when estimating TC (#129683)
getLoopEstimatedTripCount returns std::nullopt when the trip count would
overflow the return type, but since it is an estimate anyway, we might
as well saturate at UINT_MAX, improving results.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index ec1692a..42c70d2 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -843,9 +843,9 @@ static std::optional<unsigned> getEstimatedTripCount(BranchInst *ExitingBranch, // edge exiting the loop, rounded to nearest. uint64_t ExitCount = llvm::divideNearest(LoopWeight, ExitWeight); - // When ExitCount + 1 would wrap in unsigned, return std::nullopt instead. + // When ExitCount + 1 would wrap in unsigned, saturate at UINT_MAX. if (ExitCount >= std::numeric_limits<unsigned>::max()) - return std::nullopt; + return std::numeric_limits<unsigned>::max(); // Estimated trip count is one plus estimated exit count. return ExitCount + 1; |