aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopPeel.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2025-06-10 08:29:42 +0100
committerGitHub <noreply@github.com>2025-06-10 08:29:42 +0100
commite5ff7055beb116f103f030d992fadea49c994511 (patch)
tree313b453c47ce60f03c491037ed591456c69f517a /llvm/lib/Transforms/Utils/LoopPeel.cpp
parent20e8de9c8f4cf54c6c57535428c987d921861034 (diff)
downloadllvm-e5ff7055beb116f103f030d992fadea49c994511.zip
llvm-e5ff7055beb116f103f030d992fadea49c994511.tar.gz
llvm-e5ff7055beb116f103f030d992fadea49c994511.tar.bz2
[LoopPeel] Use loop guards when checking if last iter can be peeled. (#142605)
Apply loop guards to BTC before checking if the last iteration should be peeled off. This also adds an assert to make sure applying the guards does not pessimize the results. I checked on a large test set and it did not trigger there, but it adds an additional guard to catch potential cases where loop-guards pessimize results. Peels ~15% more loops. PR: https://github.com/llvm/llvm-project/pull/142605
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopPeel.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopPeel.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 9149f71..f343962 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -374,6 +374,9 @@ static bool shouldPeelLastIteration(Loop &L, CmpPredicate Pred,
L.getLoopPredecessor()->getTerminator()))
return false;
+ auto Guards = ScalarEvolution::LoopGuards::collect(&L, SE);
+ BTC = SE.applyLoopGuards(BTC, Guards);
+ RightSCEV = SE.applyLoopGuards(RightSCEV, Guards);
const SCEV *ValAtLastIter = LeftAR->evaluateAtIteration(BTC, SE);
const SCEV *ValAtSecondToLastIter = LeftAR->evaluateAtIteration(
SE.getMinusSCEV(BTC, SE.getOne(BTC->getType())), SE);