@@ -537,8 +537,8 @@ class InnerLoopVectorizer {
537537
538538 // / Set up the values of the IVs correctly when exiting the vector loop.
539539 virtual void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
540- Value *VectorTripCount, Value *EndValue ,
541- BasicBlock *MiddleBlock, VPTransformState &State);
540+ Value *VectorTripCount, BasicBlock *MiddleBlock ,
541+ VPTransformState &State);
542542
543543 // / Iteratively sink the scalarized operands of a predicated instruction into
544544 // / the block that was created for it.
@@ -651,10 +651,6 @@ class InnerLoopVectorizer {
651651 // Record whether runtime checks are added.
652652 bool AddedSafetyChecks = false ;
653653
654- // Holds the end values for each induction variable. We save the end values
655- // so we can later fix-up the external users of the induction variables.
656- DenseMap<PHINode *, Value *> IVEndValues;
657-
658654 // / BFI and PSI are used to check for profile guided size optimizations.
659655 BlockFrequencyInfo *BFI;
660656 ProfileSummaryInfo *PSI;
@@ -766,8 +762,7 @@ class EpilogueVectorizerMainLoop : public InnerLoopAndEpilogueVectorizer {
766762 void printDebugTracesAtEnd () override ;
767763
768764 void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
769- Value *VectorTripCount, Value *EndValue,
770- BasicBlock *MiddleBlock,
765+ Value *VectorTripCount, BasicBlock *MiddleBlock,
771766 VPTransformState &State) override {};
772767};
773768
@@ -2599,7 +2594,7 @@ PHINode *InnerLoopVectorizer::createInductionResumeValue(
25992594 assert (VectorTripCount && " Expected valid arguments" );
26002595
26012596 Instruction *OldInduction = Legal->getPrimaryInduction ();
2602- Value *& EndValue = IVEndValues[OrigPhi] ;
2597+ Value *EndValue = nullptr ;
26032598 Value *EndValueFromAdditionalBypass = AdditionalBypass.second ;
26042599 if (OrigPhi == OldInduction) {
26052600 // We know what the end value is.
@@ -2756,7 +2751,7 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton(
27562751// value for the IV when arriving directly from the middle block.
27572752void InnerLoopVectorizer::fixupIVUsers (PHINode *OrigPhi,
27582753 const InductionDescriptor &II,
2759- Value *VectorTripCount, Value *EndValue,
2754+ Value *VectorTripCount,
27602755 BasicBlock *MiddleBlock,
27612756 VPTransformState &State) {
27622757 // There are two kinds of external IV usages - those that use the value
@@ -2768,6 +2763,10 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
27682763
27692764 DenseMap<Value *, Value *> MissingVals;
27702765
2766+ Value *EndValue = cast<PHINode>(OrigPhi->getIncomingValueForBlock (
2767+ OrigLoop->getLoopPreheader ()))
2768+ ->getIncomingValueForBlock (MiddleBlock);
2769+
27712770 // An external user of the last iteration's value should see the value that
27722771 // the remainder loop uses to initialize its own IV.
27732772 Value *PostInc = OrigPhi->getIncomingValueForBlock (OrigLoop->getLoopLatch ());
@@ -2970,8 +2969,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
29702969 // Fix-up external users of the induction variables.
29712970 for (const auto &Entry : Legal->getInductionVars ())
29722971 fixupIVUsers (Entry.first , Entry.second ,
2973- getOrCreateVectorTripCount (nullptr ),
2974- IVEndValues[Entry.first ], LoopMiddleBlock, State);
2972+ getOrCreateVectorTripCount (nullptr ), LoopMiddleBlock, State);
29752973 }
29762974
29772975 for (Instruction *PI : PredicatedInstructions)
0 commit comments