Revert "[LV] Remove unneeded createHeaderBranch.(NFCI)"
This reverts commit 32bc83d11e19b8a8c15df81b32fde1f9f8c6156b. This is causing bots with expensive-checks to fail. Revert while I investigate.
This commit is contained in:
parent
acf83abcbf
commit
2760cdc9c6
@ -569,6 +569,11 @@ protected:
|
|||||||
Value *CountRoundDown, Value *EndValue,
|
Value *CountRoundDown, Value *EndValue,
|
||||||
BasicBlock *MiddleBlock, BasicBlock *VectorHeader);
|
BasicBlock *MiddleBlock, BasicBlock *VectorHeader);
|
||||||
|
|
||||||
|
/// Introduce a conditional branch (on true, condition to be set later) at the
|
||||||
|
/// end of the header=latch connecting it to itself (across the backedge) and
|
||||||
|
/// to the exit block of \p L.
|
||||||
|
void createHeaderBranch(Loop *L);
|
||||||
|
|
||||||
/// Handle all cross-iteration phis in the header.
|
/// Handle all cross-iteration phis in the header.
|
||||||
void fixCrossIterationPHIs(VPTransformState &State);
|
void fixCrossIterationPHIs(VPTransformState &State);
|
||||||
|
|
||||||
@ -626,8 +631,8 @@ protected:
|
|||||||
|
|
||||||
/// Emit basic blocks (prefixed with \p Prefix) for the iteration check,
|
/// Emit basic blocks (prefixed with \p Prefix) for the iteration check,
|
||||||
/// vector loop preheader, middle block and scalar preheader. Also
|
/// vector loop preheader, middle block and scalar preheader. Also
|
||||||
/// allocate a loop object for the new vector loop.
|
/// allocate a loop object for the new vector loop and return it.
|
||||||
void createVectorLoopSkeleton(StringRef Prefix);
|
Loop *createVectorLoopSkeleton(StringRef Prefix);
|
||||||
|
|
||||||
/// Create new phi nodes for the induction variables to resume iteration count
|
/// Create new phi nodes for the induction variables to resume iteration count
|
||||||
/// in the scalar epilogue, from where the vectorized loop left off.
|
/// in the scalar epilogue, from where the vectorized loop left off.
|
||||||
@ -2828,6 +2833,23 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr,
|
|||||||
PredicatedInstructions.push_back(Cloned);
|
PredicatedInstructions.push_back(Cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InnerLoopVectorizer::createHeaderBranch(Loop *L) {
|
||||||
|
BasicBlock *Header = L->getHeader();
|
||||||
|
assert(!L->getLoopLatch() && "loop should not have a latch at this point");
|
||||||
|
|
||||||
|
IRBuilder<> B(Header->getTerminator());
|
||||||
|
Instruction *OldInst =
|
||||||
|
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction());
|
||||||
|
setDebugLocFromInst(OldInst, &B);
|
||||||
|
|
||||||
|
// Connect the header to the exit and header blocks and replace the old
|
||||||
|
// terminator.
|
||||||
|
B.CreateCondBr(B.getTrue(), L->getUniqueExitBlock(), Header);
|
||||||
|
|
||||||
|
// Now we have two terminators. Remove the old one from the block.
|
||||||
|
Header->getTerminator()->eraseFromParent();
|
||||||
|
}
|
||||||
|
|
||||||
Value *InnerLoopVectorizer::getOrCreateTripCount(BasicBlock *InsertBlock) {
|
Value *InnerLoopVectorizer::getOrCreateTripCount(BasicBlock *InsertBlock) {
|
||||||
if (TripCount)
|
if (TripCount)
|
||||||
return TripCount;
|
return TripCount;
|
||||||
@ -3070,7 +3092,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
|
|||||||
return MemCheckBlock;
|
return MemCheckBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerLoopVectorizer::createVectorLoopSkeleton(StringRef Prefix) {
|
Loop *InnerLoopVectorizer::createVectorLoopSkeleton(StringRef Prefix) {
|
||||||
LoopScalarBody = OrigLoop->getHeader();
|
LoopScalarBody = OrigLoop->getHeader();
|
||||||
LoopVectorPreHeader = OrigLoop->getLoopPreheader();
|
LoopVectorPreHeader = OrigLoop->getLoopPreheader();
|
||||||
assert(LoopVectorPreHeader && "Invalid loop structure");
|
assert(LoopVectorPreHeader && "Invalid loop structure");
|
||||||
@ -3128,6 +3150,7 @@ void InnerLoopVectorizer::createVectorLoopSkeleton(StringRef Prefix) {
|
|||||||
LI->addTopLevelLoop(Lp);
|
LI->addTopLevelLoop(Lp);
|
||||||
}
|
}
|
||||||
Lp->addBasicBlockToLoop(LoopVectorBody, *LI);
|
Lp->addBasicBlockToLoop(LoopVectorBody, *LI);
|
||||||
|
return Lp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerLoopVectorizer::createInductionResumeValues(
|
void InnerLoopVectorizer::createInductionResumeValues(
|
||||||
@ -3293,7 +3316,7 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton() {
|
|||||||
|
|
||||||
// Create an empty vector loop, and prepare basic blocks for the runtime
|
// Create an empty vector loop, and prepare basic blocks for the runtime
|
||||||
// checks.
|
// checks.
|
||||||
createVectorLoopSkeleton("");
|
Loop *Lp = createVectorLoopSkeleton("");
|
||||||
|
|
||||||
// Now, compare the new count to zero. If it is zero skip the vector loop and
|
// Now, compare the new count to zero. If it is zero skip the vector loop and
|
||||||
// jump to the scalar loop. This check also covers the case where the
|
// jump to the scalar loop. This check also covers the case where the
|
||||||
@ -3311,6 +3334,8 @@ InnerLoopVectorizer::createVectorizedLoopSkeleton() {
|
|||||||
// faster.
|
// faster.
|
||||||
emitMemRuntimeChecks(LoopScalarPreHeader);
|
emitMemRuntimeChecks(LoopScalarPreHeader);
|
||||||
|
|
||||||
|
createHeaderBranch(Lp);
|
||||||
|
|
||||||
// Emit phis for the new starting index of the scalar loop.
|
// Emit phis for the new starting index of the scalar loop.
|
||||||
createInductionResumeValues();
|
createInductionResumeValues();
|
||||||
|
|
||||||
@ -7597,7 +7622,7 @@ void LoopVectorizationPlanner::executePlan(ElementCount BestVF, unsigned BestUF,
|
|||||||
// 1. Create a new empty loop. Unlink the old loop and connect the new one.
|
// 1. Create a new empty loop. Unlink the old loop and connect the new one.
|
||||||
VPTransformState State{BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan};
|
VPTransformState State{BestVF, BestUF, LI, DT, ILV.Builder, &ILV, &BestVPlan};
|
||||||
Value *CanonicalIVStartValue;
|
Value *CanonicalIVStartValue;
|
||||||
std::tie(State.CFG.VectorPreHeader, CanonicalIVStartValue) =
|
std::tie(State.CFG.PrevBB, CanonicalIVStartValue) =
|
||||||
ILV.createVectorizedLoopSkeleton();
|
ILV.createVectorizedLoopSkeleton();
|
||||||
ILV.collectPoisonGeneratingRecipes(State);
|
ILV.collectPoisonGeneratingRecipes(State);
|
||||||
|
|
||||||
@ -7714,7 +7739,7 @@ Value *InnerLoopUnroller::getBroadcastInstrs(Value *V) { return V; }
|
|||||||
std::pair<BasicBlock *, Value *>
|
std::pair<BasicBlock *, Value *>
|
||||||
EpilogueVectorizerMainLoop::createEpilogueVectorizedLoopSkeleton() {
|
EpilogueVectorizerMainLoop::createEpilogueVectorizedLoopSkeleton() {
|
||||||
MDNode *OrigLoopID = OrigLoop->getLoopID();
|
MDNode *OrigLoopID = OrigLoop->getLoopID();
|
||||||
createVectorLoopSkeleton("");
|
Loop *Lp = createVectorLoopSkeleton("");
|
||||||
|
|
||||||
// Generate the code to check the minimum iteration count of the vector
|
// Generate the code to check the minimum iteration count of the vector
|
||||||
// epilogue (see below).
|
// epilogue (see below).
|
||||||
@ -7743,6 +7768,7 @@ EpilogueVectorizerMainLoop::createEpilogueVectorizedLoopSkeleton() {
|
|||||||
// Generate the induction variable.
|
// Generate the induction variable.
|
||||||
Value *CountRoundDown = getOrCreateVectorTripCount(LoopVectorPreHeader);
|
Value *CountRoundDown = getOrCreateVectorTripCount(LoopVectorPreHeader);
|
||||||
EPI.VectorTripCount = CountRoundDown;
|
EPI.VectorTripCount = CountRoundDown;
|
||||||
|
createHeaderBranch(Lp);
|
||||||
|
|
||||||
// Skip induction resume value creation here because they will be created in
|
// Skip induction resume value creation here because they will be created in
|
||||||
// the second pass. If we created them here, they wouldn't be used anyway,
|
// the second pass. If we created them here, they wouldn't be used anyway,
|
||||||
@ -7834,7 +7860,7 @@ EpilogueVectorizerMainLoop::emitMinimumIterationCountCheck(BasicBlock *Bypass,
|
|||||||
std::pair<BasicBlock *, Value *>
|
std::pair<BasicBlock *, Value *>
|
||||||
EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
|
EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
|
||||||
MDNode *OrigLoopID = OrigLoop->getLoopID();
|
MDNode *OrigLoopID = OrigLoop->getLoopID();
|
||||||
createVectorLoopSkeleton("vec.epilog.");
|
Loop *Lp = createVectorLoopSkeleton("vec.epilog.");
|
||||||
|
|
||||||
// Now, compare the remaining count and if there aren't enough iterations to
|
// Now, compare the remaining count and if there aren't enough iterations to
|
||||||
// execute the vectorized epilogue skip to the scalar part.
|
// execute the vectorized epilogue skip to the scalar part.
|
||||||
@ -7915,6 +7941,9 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
|
|||||||
EPResumeVal->addIncoming(ConstantInt::get(IdxTy, 0),
|
EPResumeVal->addIncoming(ConstantInt::get(IdxTy, 0),
|
||||||
EPI.MainLoopIterationCountCheck);
|
EPI.MainLoopIterationCountCheck);
|
||||||
|
|
||||||
|
// Generate the induction variable.
|
||||||
|
createHeaderBranch(Lp);
|
||||||
|
|
||||||
// Generate induction resume values. These variables save the new starting
|
// Generate induction resume values. These variables save the new starting
|
||||||
// indexes for the scalar loop. They are used to test if there are any tail
|
// indexes for the scalar loop. They are used to test if there are any tail
|
||||||
// iterations left once the vector loop has completed.
|
// iterations left once the vector loop has completed.
|
||||||
|
@ -857,7 +857,7 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
|
|||||||
|
|
||||||
// Check if the backedge taken count is needed, and if so build it.
|
// Check if the backedge taken count is needed, and if so build it.
|
||||||
if (BackedgeTakenCount && BackedgeTakenCount->getNumUsers()) {
|
if (BackedgeTakenCount && BackedgeTakenCount->getNumUsers()) {
|
||||||
IRBuilder<> Builder(State.CFG.VectorPreHeader->getTerminator());
|
IRBuilder<> Builder(State.CFG.PrevBB->getTerminator());
|
||||||
auto *TCMO = Builder.CreateSub(TripCountV,
|
auto *TCMO = Builder.CreateSub(TripCountV,
|
||||||
ConstantInt::get(TripCountV->getType(), 1),
|
ConstantInt::get(TripCountV->getType(), 1),
|
||||||
"trip.count.minus.1");
|
"trip.count.minus.1");
|
||||||
@ -898,16 +898,17 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
|
|||||||
/// LoopVectorBody basic-block was created for this. Introduce additional
|
/// LoopVectorBody basic-block was created for this. Introduce additional
|
||||||
/// basic-blocks as needed, and fill them all.
|
/// basic-blocks as needed, and fill them all.
|
||||||
void VPlan::execute(VPTransformState *State) {
|
void VPlan::execute(VPTransformState *State) {
|
||||||
// Set the reverse mapping from VPValues to Values for code generation.
|
// 0. Set the reverse mapping from VPValues to Values for code generation.
|
||||||
for (auto &Entry : Value2VPValue)
|
for (auto &Entry : Value2VPValue)
|
||||||
State->VPValue2Value[Entry.second] = Entry.first;
|
State->VPValue2Value[Entry.second] = Entry.first;
|
||||||
|
|
||||||
// Initialize CFG state.
|
BasicBlock *VectorPreHeaderBB = State->CFG.PrevBB;
|
||||||
State->CFG.PrevVPBB = nullptr;
|
State->CFG.VectorPreHeader = VectorPreHeaderBB;
|
||||||
BasicBlock *VectorHeaderBB = State->CFG.VectorPreHeader->getSingleSuccessor();
|
BasicBlock *VectorHeaderBB = VectorPreHeaderBB->getSingleSuccessor();
|
||||||
State->CFG.PrevBB = VectorHeaderBB;
|
assert(VectorHeaderBB && "Loop preheader does not have a single successor.");
|
||||||
State->CFG.ExitBB = VectorHeaderBB->getSingleSuccessor();
|
|
||||||
State->CurrentVectorLoop = State->LI->getLoopFor(VectorHeaderBB);
|
State->CurrentVectorLoop = State->LI->getLoopFor(VectorHeaderBB);
|
||||||
|
State->CFG.ExitBB = State->CurrentVectorLoop->getExitBlock();
|
||||||
|
|
||||||
// Remove the edge between Header and Latch to allow other connections.
|
// Remove the edge between Header and Latch to allow other connections.
|
||||||
// Temporarily terminate with unreachable until CFG is rewired.
|
// Temporarily terminate with unreachable until CFG is rewired.
|
||||||
@ -919,6 +920,9 @@ void VPlan::execute(VPTransformState *State) {
|
|||||||
State->Builder.SetInsertPoint(Terminator);
|
State->Builder.SetInsertPoint(Terminator);
|
||||||
|
|
||||||
// Generate code in loop body.
|
// Generate code in loop body.
|
||||||
|
State->CFG.PrevVPBB = nullptr;
|
||||||
|
State->CFG.PrevBB = VectorHeaderBB;
|
||||||
|
|
||||||
for (VPBlockBase *Block : depth_first(Entry))
|
for (VPBlockBase *Block : depth_first(Entry))
|
||||||
Block->execute(State);
|
Block->execute(State);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user