-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[VPlan] Use DomTreeUpdater to automatically update DT for vector loop. #92525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c51627
[VPlan] Use DomTreeUpdater to automatically update DT for vector loop.
fhahn 662499c
Merge remote-tracking branch 'origin/main' into vplan-dtu
fhahn 17036a2
!fixup move DTU to CFG, dont use for native-path
fhahn e31385a
!fixup retain more
fhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,6 +25,7 @@ | |||||||||||
#include "llvm/ADT/SmallVector.h" | ||||||||||||
#include "llvm/ADT/StringExtras.h" | ||||||||||||
#include "llvm/ADT/Twine.h" | ||||||||||||
#include "llvm/Analysis/DomTreeUpdater.h" | ||||||||||||
#include "llvm/Analysis/LoopInfo.h" | ||||||||||||
#include "llvm/IR/BasicBlock.h" | ||||||||||||
#include "llvm/IR/CFG.h" | ||||||||||||
|
@@ -218,7 +219,7 @@ VPTransformState::VPTransformState(ElementCount VF, unsigned UF, LoopInfo *LI, | |||||||||||
DominatorTree *DT, IRBuilderBase &Builder, | ||||||||||||
InnerLoopVectorizer *ILV, VPlan *Plan, | ||||||||||||
LLVMContext &Ctx) | ||||||||||||
: VF(VF), UF(UF), LI(LI), DT(DT), Builder(Builder), ILV(ILV), Plan(Plan), | ||||||||||||
: VF(VF), UF(UF), CFG(DT), LI(LI), Builder(Builder), ILV(ILV), Plan(Plan), | ||||||||||||
LVer(nullptr), | ||||||||||||
TypeAnalysis(Plan->getCanonicalIV()->getScalarType(), Ctx) {} | ||||||||||||
|
||||||||||||
|
@@ -436,6 +437,7 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) { | |||||||||||
"Trying to reset an existing successor block."); | ||||||||||||
TermBr->setSuccessor(idx, NewBB); | ||||||||||||
} | ||||||||||||
CFG.DTU.applyUpdates({{DominatorTree::Insert, PredBB, NewBB}}); | ||||||||||||
} | ||||||||||||
return NewBB; | ||||||||||||
} | ||||||||||||
|
@@ -467,6 +469,7 @@ void VPBasicBlock::execute(VPTransformState *State) { | |||||||||||
// The Exit block of a loop is always set to be successor 0 of the Exiting | ||||||||||||
// block. | ||||||||||||
cast<BranchInst>(ExitingBB->getTerminator())->setSuccessor(0, NewBB); | ||||||||||||
State->CFG.DTU.applyUpdates({{DominatorTree::Insert, ExitingBB, NewBB}}); | ||||||||||||
} else if (PrevVPBB && /* A */ | ||||||||||||
!((SingleHPred = getSingleHierarchicalPredecessor()) && | ||||||||||||
SingleHPred->getExitingBasicBlock() == PrevVPBB && | ||||||||||||
|
@@ -829,6 +832,11 @@ void VPlan::execute(VPTransformState *State) { | |||||||||||
BasicBlock *VectorPreHeader = State->CFG.PrevBB; | ||||||||||||
State->Builder.SetInsertPoint(VectorPreHeader->getTerminator()); | ||||||||||||
|
||||||||||||
// Disconnect VectorPreHeader from ExitBB in both the CFG and DT. | ||||||||||||
cast<BranchInst>(VectorPreHeader->getTerminator())->setSuccessor(0, nullptr); | ||||||||||||
State->CFG.DTU.applyUpdates( | ||||||||||||
{{DominatorTree::Delete, VectorPreHeader, State->CFG.ExitBB}}); | ||||||||||||
|
||||||||||||
// Generate code in the loop pre-header and body. | ||||||||||||
for (VPBlockBase *Block : vp_depth_first_shallow(Entry)) | ||||||||||||
Block->execute(State); | ||||||||||||
|
@@ -891,13 +899,10 @@ void VPlan::execute(VPTransformState *State) { | |||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// We do not attempt to preserve DT for outer loop vectorization currently. | ||||||||||||
if (!EnableVPlanNativePath) { | ||||||||||||
BasicBlock *VectorHeaderBB = State->CFG.VPBB2IRBB[Header]; | ||||||||||||
State->DT->addNewBlock(VectorHeaderBB, VectorPreHeader); | ||||||||||||
updateDominatorTree(State->DT, VectorHeaderBB, VectorLatchBB, | ||||||||||||
State->CFG.ExitBB); | ||||||||||||
} | ||||||||||||
State->CFG.DTU.flush(); | ||||||||||||
// DT is currently updated for non-native path only. | ||||||||||||
assert(EnableVPlanNativePath || State->CFG.DTU.getDomTree().verify( | ||||||||||||
DominatorTree::VerificationLevel::Fast)); | ||||||||||||
Comment on lines
+904
to
+905
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(retaining the comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added back, thanks! |
||||||||||||
} | ||||||||||||
|
||||||||||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||||||||||||
|
@@ -995,44 +1000,6 @@ void VPlan::addLiveOut(PHINode *PN, VPValue *V) { | |||||||||||
LiveOuts.insert({PN, new VPLiveOut(PN, V)}); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void VPlan::updateDominatorTree(DominatorTree *DT, BasicBlock *LoopHeaderBB, | ||||||||||||
BasicBlock *LoopLatchBB, | ||||||||||||
BasicBlock *LoopExitBB) { | ||||||||||||
// The vector body may be more than a single basic-block by this point. | ||||||||||||
// Update the dominator tree information inside the vector body by propagating | ||||||||||||
// it from header to latch, expecting only triangular control-flow, if any. | ||||||||||||
BasicBlock *PostDomSucc = nullptr; | ||||||||||||
for (auto *BB = LoopHeaderBB; BB != LoopLatchBB; BB = PostDomSucc) { | ||||||||||||
// Get the list of successors of this block. | ||||||||||||
std::vector<BasicBlock *> Succs(succ_begin(BB), succ_end(BB)); | ||||||||||||
assert(Succs.size() <= 2 && | ||||||||||||
"Basic block in vector loop has more than 2 successors."); | ||||||||||||
PostDomSucc = Succs[0]; | ||||||||||||
if (Succs.size() == 1) { | ||||||||||||
assert(PostDomSucc->getSinglePredecessor() && | ||||||||||||
"PostDom successor has more than one predecessor."); | ||||||||||||
DT->addNewBlock(PostDomSucc, BB); | ||||||||||||
continue; | ||||||||||||
} | ||||||||||||
BasicBlock *InterimSucc = Succs[1]; | ||||||||||||
if (PostDomSucc->getSingleSuccessor() == InterimSucc) { | ||||||||||||
PostDomSucc = Succs[1]; | ||||||||||||
InterimSucc = Succs[0]; | ||||||||||||
} | ||||||||||||
assert(InterimSucc->getSingleSuccessor() == PostDomSucc && | ||||||||||||
"One successor of a basic block does not lead to the other."); | ||||||||||||
assert(InterimSucc->getSinglePredecessor() && | ||||||||||||
"Interim successor has more than one predecessor."); | ||||||||||||
assert(PostDomSucc->hasNPredecessors(2) && | ||||||||||||
"PostDom successor has more than two predecessors."); | ||||||||||||
DT->addNewBlock(InterimSucc, BB); | ||||||||||||
DT->addNewBlock(PostDomSucc, BB); | ||||||||||||
} | ||||||||||||
// Latch block is a new dominator for the loop exit. | ||||||||||||
DT->changeImmediateDominator(LoopExitBB, LoopLatchBB); | ||||||||||||
assert(DT->verify(DominatorTree::VerificationLevel::Fast)); | ||||||||||||
} | ||||||||||||
|
||||||||||||
static void remapOperands(VPBlockBase *Entry, VPBlockBase *NewEntry, | ||||||||||||
DenseMap<VPValue *, VPValue *> &Old2NewVPValues) { | ||||||||||||
// Update the operands of all cloned recipes starting at NewEntry. This | ||||||||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExitBB is (still, the single) successor of PrevBB=VectorPreHeader, should they first be disconnected before updating DTU with their edge's deletion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated to remove the edge before