Skip to content

Commit 5ebec5d

Browse files
committed
Add check for ensure the loop of SCEVAddRec is the same as the loop of reduction phi
1 parent 69cd172 commit 5ebec5d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class RecurrenceDescriptor {
165165
/// other is a PHI value.
166166
// TODO: Support non-monotonic variable. FindLast does not need be restricted
167167
// to increasing loop induction variables.
168-
static InstDesc isFindLastIVPattern(PHINode *OrigPhi, Instruction *I,
169-
ScalarEvolution &SE);
168+
static InstDesc isFindLastIVPattern(Loop *TheLoop, PHINode *OrigPhi,
169+
Instruction *I, ScalarEvolution &SE);
170170

171171
/// Returns a struct describing if the instruction is a
172172
/// Select(FCmp(X, Y), (Z = X op PHINode), PHINode) instruction pattern.

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
688688
// value of the data type or a non-constant value by using mask and multiple
689689
// reduction operations.
690690
RecurrenceDescriptor::InstDesc
691-
RecurrenceDescriptor::isFindLastIVPattern(PHINode *OrigPhi, Instruction *I,
692-
ScalarEvolution &SE) {
691+
RecurrenceDescriptor::isFindLastIVPattern(Loop *TheLoop, PHINode *OrigPhi,
692+
Instruction *I, ScalarEvolution &SE) {
693693
// TODO: Support the vectorization of FindLastIV when the reduction phi is
694694
// used by more than one select instruction. This vectorization is only
695695
// performed when the SCEV of each increasing induction variable used by the
@@ -711,7 +711,7 @@ RecurrenceDescriptor::isFindLastIVPattern(PHINode *OrigPhi, Instruction *I,
711711
return false;
712712

713713
auto *AR = dyn_cast<SCEVAddRecExpr>(SE.getSCEV(V));
714-
if (!AR)
714+
if (!AR || AR->getLoop() != TheLoop)
715715
return false;
716716

717717
const SCEV *Step = AR->getStepRecurrence(SE);
@@ -880,7 +880,7 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(
880880
Kind == RecurKind::Add || Kind == RecurKind::Mul)
881881
return isConditionalRdxPattern(Kind, I);
882882
if (isFindLastIVRecurrenceKind(Kind) && SE)
883-
return isFindLastIVPattern(OrigPhi, I, *SE);
883+
return isFindLastIVPattern(L, OrigPhi, I, *SE);
884884
[[fallthrough]];
885885
case Instruction::FCmp:
886886
case Instruction::ICmp:

0 commit comments

Comments
 (0)