@@ -546,8 +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, VPTransformState &State);
549+ Value *VectorTripCount, BasicBlock *MiddleBlock ,
550+ VPTransformState &State);
551551
552552 // / Iteratively sink the scalarized operands of a predicated instruction into
553553 // / the block that was created for it.
@@ -664,10 +664,6 @@ class InnerLoopVectorizer {
664664 // Record whether runtime checks are added.
665665 bool AddedSafetyChecks = false ;
666666
667- // Holds the end values for each induction variable. We save the end values
668- // so we can later fix-up the external users of the induction variables.
669- DenseMap<PHINode *, Value *> IVEndValues;
670-
671667 // / BFI and PSI are used to check for profile guided size optimizations.
672668 BlockFrequencyInfo *BFI;
673669 ProfileSummaryInfo *PSI;
@@ -782,8 +778,7 @@ class EpilogueVectorizerMainLoop : public InnerLoopAndEpilogueVectorizer {
782778 void printDebugTracesAtEnd () override ;
783779
784780 void fixupIVUsers (PHINode *OrigPhi, const InductionDescriptor &II,
785- Value *VectorTripCount, Value *EndValue,
786- BasicBlock *MiddleBlock,
781+ Value *VectorTripCount, BasicBlock *MiddleBlock,
787782 VPTransformState &State) override {};
788783};
789784
@@ -2615,7 +2610,7 @@ void InnerLoopVectorizer::createInductionResumeValue(
26152610 assert (VectorTripCount && " Expected valid arguments" );
26162611
26172612 Instruction *OldInduction = Legal->getPrimaryInduction ();
2618- Value *& EndValue = IVEndValues[OrigPhi] ;
2613+ Value *EndValue = nullptr ;
26192614 Value *EndValueFromAdditionalBypass = AdditionalBypass.second ;
26202615 if (OrigPhi == OldInduction) {
26212616 // We know what the end value is.
@@ -2771,7 +2766,7 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton(
27712766// value for the IV when arriving directly from the middle block.
27722767void InnerLoopVectorizer::fixupIVUsers (PHINode *OrigPhi,
27732768 const InductionDescriptor &II,
2774- Value *VectorTripCount, Value *EndValue,
2769+ Value *VectorTripCount,
27752770 BasicBlock *MiddleBlock,
27762771 VPTransformState &State) {
27772772 // There are two kinds of external IV usages - those that use the value
@@ -2783,6 +2778,10 @@ void InnerLoopVectorizer::fixupIVUsers(PHINode *OrigPhi,
27832778
27842779 DenseMap<Value *, Value *> MissingVals;
27852780
2781+ Value *EndValue = cast<PHINode>(OrigPhi->getIncomingValueForBlock (
2782+ OrigLoop->getLoopPreheader ()))
2783+ ->getIncomingValueForBlock (MiddleBlock);
2784+
27862785 // An external user of the last iteration's value should see the value that
27872786 // the remainder loop uses to initialize its own IV.
27882787 Value *PostInc = OrigPhi->getIncomingValueForBlock (OrigLoop->getLoopLatch ());
@@ -2985,8 +2984,8 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
29852984 // Fix-up external users of the induction variables.
29862985 for (const auto &Entry : Legal->getInductionVars ())
29872986 fixupIVUsers (Entry.first , Entry.second ,
2988- getOrCreateVectorTripCount (nullptr ),
2989- IVEndValues[Entry. first ], LoopMiddleBlock, State);
2987+ getOrCreateVectorTripCount (nullptr ), LoopMiddleBlock,
2988+ State);
29902989 }
29912990
29922991 for (Instruction *PI : PredicatedInstructions)
0 commit comments