Skip to content

Commit 2b125e8

Browse files
committed
[LV] Don't pass loop preheader to getOrCreateVectorTripCount (NFCI).
The vector trip count must already be created when fixupIVUsers is called. Don't pass the vector preheader there and delay retrieving the vector loop header. This ensures we are re-using the already computed trip count. Computing the trip count from scratch would not be correct, as the IR may not be in a valid state yet.
1 parent 639a0af commit 2b125e8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,9 +2933,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29332933
for (PHINode &PN : Exit->phis())
29342934
PSE.getSE()->forgetLcssaPhiWithNewPredecessor(OrigLoop, &PN);
29352935

2936-
VPRegionBlock *VectorRegion = State.Plan->getVectorLoopRegion();
2937-
VPBasicBlock *LatchVPBB = VectorRegion->getExitingBasicBlock();
2938-
Loop *VectorLoop = LI->getLoopFor(State.CFG.VPBB2IRBB[LatchVPBB]);
29392936
if (Cost->requiresScalarEpilogue(VF.isVector())) {
29402937
// No edge from the middle block to the unique exit block has been inserted
29412938
// and there is nothing to fix from vector loop; phis should have incoming
@@ -2951,7 +2948,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29512948
// Fix-up external users of the induction variables.
29522949
for (const auto &Entry : Legal->getInductionVars())
29532950
fixupIVUsers(Entry.first, Entry.second,
2954-
getOrCreateVectorTripCount(VectorLoop->getLoopPreheader()),
2951+
getOrCreateVectorTripCount(nullptr),
29552952
IVEndValues[Entry.first], LoopMiddleBlock, Plan, State);
29562953
}
29572954

@@ -2962,8 +2959,12 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29622959
for (Instruction *PI : PredicatedInstructions)
29632960
sinkScalarOperands(&*PI);
29642961

2962+
VPRegionBlock *VectorRegion = State.Plan->getVectorLoopRegion();
2963+
VPBasicBlock *HeaderVPBB = VectorRegion->getEntryBasicBlock();
2964+
BasicBlock *HeaderBB = State.CFG.VPBB2IRBB[HeaderVPBB];
2965+
29652966
// Remove redundant induction instructions.
2966-
cse(VectorLoop->getHeader());
2967+
cse(HeaderBB);
29672968

29682969
// Set/update profile weights for the vector and remainder loops as original
29692970
// loop iterations are now distributed among them. Note that original loop
@@ -2978,8 +2979,9 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State,
29782979
// For scalable vectorization we can't know at compile time how many iterations
29792980
// of the loop are handled in one vector iteration, so instead assume a pessimistic
29802981
// vscale of '1'.
2981-
setProfileInfoAfterUnrolling(LI->getLoopFor(LoopScalarBody), VectorLoop,
2982-
LI->getLoopFor(LoopScalarBody),
2982+
Loop *ScalarLoop = LI->getLoopFor(LoopScalarBody);
2983+
Loop *VectorLoop = LI->getLoopFor(HeaderBB);
2984+
setProfileInfoAfterUnrolling(ScalarLoop, VectorLoop, ScalarLoop,
29832985
VF.getKnownMinValue() * UF);
29842986
}
29852987

0 commit comments

Comments
 (0)