Skip to content

Commit f755e66

Browse files
committed
[LoopPeel] Make sure AddRec is for correct loop when peeling last iter.
Follow-up to post-commit comment for (#139551. This should effectively be NFC, given the other existing restrictions.
1 parent 49c39ef commit f755e66

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/lib/Transforms/Utils/LoopPeel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Analysis/LoopIterator.h"
1919
#include "llvm/Analysis/ScalarEvolution.h"
2020
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
21+
#include "llvm/Analysis/ScalarEvolutionPatternMatch.h"
2122
#include "llvm/Analysis/TargetTransformInfo.h"
2223
#include "llvm/IR/BasicBlock.h"
2324
#include "llvm/IR/Dominators.h"
@@ -45,6 +46,7 @@
4546

4647
using namespace llvm;
4748
using namespace llvm::PatternMatch;
49+
using namespace llvm::SCEVPatternMatch;
4850

4951
#define DEBUG_TYPE "loop-peel"
5052

@@ -351,8 +353,8 @@ bool llvm::canPeelLastIteration(const Loop &L, ScalarEvolution &SE) {
351353
m_BasicBlock(Succ1), m_BasicBlock(Succ2))) &&
352354
((Pred == CmpInst::ICMP_EQ && Succ2 == L.getHeader()) ||
353355
(Pred == CmpInst::ICMP_NE && Succ1 == L.getHeader())) &&
354-
isa<SCEVAddRecExpr>(SE.getSCEV(Inc)) &&
355-
cast<SCEVAddRecExpr>(SE.getSCEV(Inc))->getStepRecurrence(SE)->isOne();
356+
match(SE.getSCEV(Inc),
357+
m_scev_AffineAddRec(m_SCEV(), m_scev_One(), m_SpecificLoop(&L)));
356358
}
357359

358360
/// Returns true if the last iteration can be peeled off and the condition (Pred

0 commit comments

Comments
 (0)