[llvm] f755e66 - [LoopPeel] Make sure AddRec is for correct loop when peeling last iter.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun May 25 04:09:26 PDT 2025
Author: Florian Hahn
Date: 2025-05-25T12:05:06+01:00
New Revision: f755e6644a5b321d16bf33bc525fff8dc59800fe
URL: https://github.com/llvm/llvm-project/commit/f755e6644a5b321d16bf33bc525fff8dc59800fe
DIFF: https://github.com/llvm/llvm-project/commit/f755e6644a5b321d16bf33bc525fff8dc59800fe.diff
LOG: [LoopPeel] Make sure AddRec is for correct loop when peeling last iter.
Follow-up to post-commit comment for
(https://github.com/llvm/llvm-project/pull/139551.
This should effectively be NFC, given the other existing restrictions.
Added:
Modified:
llvm/lib/Transforms/Utils/LoopPeel.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 4eaa3c9714370..52ce7af4252be 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -18,6 +18,7 @@
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
+#include "llvm/Analysis/ScalarEvolutionPatternMatch.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Dominators.h"
@@ -45,6 +46,7 @@
using namespace llvm;
using namespace llvm::PatternMatch;
+using namespace llvm::SCEVPatternMatch;
#define DEBUG_TYPE "loop-peel"
@@ -351,8 +353,8 @@ bool llvm::canPeelLastIteration(const Loop &L, ScalarEvolution &SE) {
m_BasicBlock(Succ1), m_BasicBlock(Succ2))) &&
((Pred == CmpInst::ICMP_EQ && Succ2 == L.getHeader()) ||
(Pred == CmpInst::ICMP_NE && Succ1 == L.getHeader())) &&
- isa<SCEVAddRecExpr>(SE.getSCEV(Inc)) &&
- cast<SCEVAddRecExpr>(SE.getSCEV(Inc))->getStepRecurrence(SE)->isOne();
+ match(SE.getSCEV(Inc),
+ m_scev_AffineAddRec(m_SCEV(), m_scev_One(), m_SpecificLoop(&L)));
}
/// Returns true if the last iteration can be peeled off and the condition (Pred
More information about the llvm-commits
mailing list