1717#include " llvm/Analysis/ScalarEvolutionExpressions.h"
1818#include " llvm/Analysis/ValueTracking.h"
1919#include " llvm/IR/Dominators.h"
20+ #include " llvm/IR/Instruction.h"
2021#include " llvm/IR/Instructions.h"
2122#include " llvm/IR/PatternMatch.h"
2223#include " llvm/IR/ValueHandle.h"
24+ #include " llvm/Support/Casting.h"
2325#include " llvm/Support/Debug.h"
2426#include " llvm/Support/KnownBits.h"
2527
@@ -693,9 +695,9 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
693695// value of the data type or a non-constant value by using mask and multiple
694696// reduction operations.
695697RecurrenceDescriptor::InstDesc
696- RecurrenceDescriptor::isFindIVPattern (RecurKind Kind, Loop *TheLoop,
697- PHINode *OrigPhi, Instruction *I,
698- ScalarEvolution &SE) {
698+ RecurrenceDescriptor::isFindPattern (RecurKind Kind, Loop *TheLoop,
699+ PHINode *OrigPhi, Instruction *I,
700+ ScalarEvolution &SE) {
699701 // TODO: Support the vectorization of FindLastIV when the reduction phi is
700702 // used by more than one select instruction. This vectorization is only
701703 // performed when the SCEV of each increasing induction variable used by the
@@ -721,16 +723,14 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
721723 return InstDesc (false , I);
722724
723725 // FIXME: Support more complex patterns, including multiple selects.
724- // Phi or Select must be used only outside the loop,
725- // except for each other.
726- if (!all_of (I->users (), [OrigPhi, TheLoop](User *U) {
727- if (U == OrigPhi)
728- return true ;
729- if (auto *UI = dyn_cast<Instruction>(U))
730- return !TheLoop->contains (UI);
731- return false ;
732- }))
726+ // The Select must be used only outside the loop and by the PHI.
727+ for (User *U : I->users ()) {
728+ if (U == OrigPhi)
729+ continue ;
730+ if (auto *UI = dyn_cast<Instruction>(U); UI && !TheLoop->contains (UI))
731+ continue ;
733732 return InstDesc (false , I);
733+ }
734734
735735 return InstDesc (I, RecurKind::FindLast);
736736 }
@@ -944,7 +944,7 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(
944944 Kind == RecurKind::Sub || Kind == RecurKind::AddChainWithSubs)
945945 return isConditionalRdxPattern (I);
946946 if ((isFindIVRecurrenceKind (Kind) || isFindLastRecurrenceKind (Kind)) && SE)
947- return isFindIVPattern (Kind, L, OrigPhi, I, *SE);
947+ return isFindPattern (Kind, L, OrigPhi, I, *SE);
948948 [[fallthrough]];
949949 case Instruction::FCmp:
950950 case Instruction::ICmp:
0 commit comments