@@ -546,9 +546,8 @@ class InnerLoopVectorizer {
546546
547547 // / Set up the values of the IVs correctly when exiting the vector loop.
548548 virtual void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
549- Value *VectorTripCount, Value *EndValue,
550- BasicBlock *MiddleBlock, VPlan &Plan,
551- VPTransformState &State);
549+ Value *VectorTripCount, BasicBlock *MiddleBlock,
550+ VPlan &Plan, VPTransformState &State);
552551
553552 // / Iteratively sink the scalarized operands of a predicated instruction into
554553 // / the block that was created for it.
@@ -665,10 +664,6 @@ class InnerLoopVectorizer {
665664 // Record whether runtime checks are added.
666665 bool AddedSafetyChecks = false ;
667666
668- // Holds the end values for each induction variable. We save the end values
669- // so we can later fix-up the external users of the induction variables.
670- DenseMap<PHINode *, Value *> IVEndValues;
671-
672667 // / BFI and PSI are used to check for profile guided size optimizations.
673668 BlockFrequencyInfo *BFI;
674669 ProfileSummaryInfo *PSI;
@@ -783,9 +778,8 @@ class EpilogueVectorizerMainLoop : public InnerLoopAndEpilogueVectorizer {
783778 void printDebugTracesAtEnd () override ;
784779
785780 void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
786- Value *VectorTripCount, Value *EndValue,
787- BasicBlock *MiddleBlock, VPlan &Plan,
788- VPTransformState &State) override {};
781+ Value *VectorTripCount, BasicBlock *MiddleBlock,
782+ VPlan &Plan, VPTransformState &State) override {};
789783};
790784
791785// A specialized derived class of inner loop vectorizer that performs
@@ -2616,7 +2610,7 @@ void InnerLoopVectorizer::createInductionResumeValue(
26162610 assert (VectorTripCount && " Expected valid arguments" );
26172611
26182612 Instruction *OldInduction = Legal->getPrimaryInduction ();
2619- Value *& EndValue = IVEndValues[OrigPhi] ;
2613+ Value *EndValue = nullptr ;
26202614 Value *EndValueFromAdditionalBypass = AdditionalBypass.second ;
26212615 if (OrigPhi == OldInduction) {
26222616 // We know what the end value is.
@@ -2771,7 +2765,7 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton(
27712765// value for the IV when arriving directly from the middle block.
27722766void InnerLoopVectorizer::fixupIVUsers (PHINode *OrigPhi,
27732767 const InductionDescriptor &II,
2774- Value *VectorTripCount, Value *EndValue,
2768+ Value *VectorTripCount,
27752769 BasicBlock *MiddleBlock, VPlan &Plan,
27762770 VPTransformState &State) {
27772771 // There are two kinds of external IV usages - those that use the value
@@ -2783,6 +2777,10 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
27832777
27842778 DenseMap<Value *, Value *> MissingVals;
27852779
2780+ Value *EndValue = cast<PHINode>(OrigPhi->getIncomingValueForBlock (
2781+ OrigLoop->getLoopPreheader ()))
2782+ ->getIncomingValueForBlock (MiddleBlock);
2783+
27862784 // An external user of the last iteration's value should see the value that
27872785 // the remainder loop uses to initialize its own IV.
27882786 Value *PostInc = OrigPhi->getIncomingValueForBlock (OrigLoop->getLoopLatch ());
@@ -2986,8 +2984,8 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29862984 // Fix-up external users of the induction variables.
29872985 for (const auto &Entry : Legal->getInductionVars ())
29882986 fixupIVUsers (Entry.first , Entry.second ,
2989- getOrCreateVectorTripCount (nullptr ),
2990- IVEndValues[Entry. first ], LoopMiddleBlock, Plan, State);
2987+ getOrCreateVectorTripCount (nullptr ), LoopMiddleBlock, Plan,
2988+ State);
29912989 }
29922990
29932991 for (Instruction *PI : PredicatedInstructions)
0 commit comments