[llvm] 4bbf371 - [SLP][NFC]Improve compile-time by using map {TreeEntry *, Instruction *}
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 18 13:29:23 PDT 2023
Author: Alexey Bataev
Date: 2023-07-18T13:24:55-07:00
New Revision: 4bbf37199c776304981fcd9107492e87d733dde6
URL: https://github.com/llvm/llvm-project/commit/4bbf37199c776304981fcd9107492e87d733dde6
DIFF: https://github.com/llvm/llvm-project/commit/4bbf37199c776304981fcd9107492e87d733dde6.diff
LOG: [SLP][NFC]Improve compile-time by using map {TreeEntry *, Instruction *}
in getLastInstructionInBundle(), NFC.
Instead of building EntryToLastInstruction before the vectorization,
build it automatically during the calls to getLastInstructionInBundle()
function.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 9e179b80298177..32279ed71f3dfb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -9015,6 +9015,9 @@ void BoUpSLP::reorderInputsAccordingToOpcode(
}
Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
+ auto &Res = EntryToLastInstruction.FindAndConstruct(E);
+ if (Res.second)
+ return *Res.second;
// Get the basic block this bundle is in. All instructions in the bundle
// should be in this block (except for extractelement-like instructions with
// constant indeces).
@@ -9029,7 +9032,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
isVectorLikeInstWithConstOps(I);
}));
- auto &&FindLastInst = [E, Front, this, &BB]() {
+ auto FindLastInst = [&]() {
Instruction *LastInst = Front;
for (Value *V : E->Scalars) {
auto *I = dyn_cast<Instruction>(V);
@@ -9065,7 +9068,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
return LastInst;
};
- auto &&FindFirstInst = [E, Front, this]() {
+ auto FindFirstInst = [&]() {
Instruction *FirstInst = Front;
for (Value *V : E->Scalars) {
auto *I = dyn_cast<Instruction>(V);
@@ -9105,7 +9108,6 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
if (doesNotNeedToSchedule(E->Scalars) ||
(E->State != TreeEntry::NeedToGather &&
all_of(E->Scalars, isVectorLikeInstWithConstOps))) {
- Instruction *InsertInst;
if ((E->getOpcode() == Instruction::GetElementPtr &&
any_of(E->Scalars,
[](Value *V) {
@@ -9114,15 +9116,12 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
all_of(E->Scalars, [](Value *V) {
return !isVectorLikeInstWithConstOps(V) && isUsedOutsideBlock(V);
}))
- InsertInst = FindLastInst();
+ Res.second = FindLastInst();
else
- InsertInst = FindFirstInst();
- return *InsertInst;
+ Res.second = FindFirstInst();
+ return *Res.second;
}
- // The last instruction in the bundle in program order.
- Instruction *LastInst = nullptr;
-
// Find the last instruction. The common case should be that BB has been
// scheduled, and the last instruction is VL.back(). So we start with
// VL.back() and iterate over schedule data until we reach the end of the
@@ -9135,7 +9134,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
if (Bundle && Bundle->isPartOfBundle())
for (; Bundle; Bundle = Bundle->NextInBundle)
if (Bundle->OpValue == Bundle->Inst)
- LastInst = Bundle->Inst;
+ Res.second = Bundle->Inst;
}
// LastInst can still be null at this point if there's either not an entry
@@ -9156,15 +9155,15 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
// not ideal. However, this should be exceedingly rare since it requires that
// we both exit early from buildTree_rec and that the bundle be out-of-order
// (causing us to iterate all the way to the end of the block).
- if (!LastInst)
- LastInst = FindLastInst();
- assert(LastInst && "Failed to find last instruction in bundle");
- return *LastInst;
+ if (!Res.second)
+ Res.second = FindLastInst();
+ assert(Res.second && "Failed to find last instruction in bundle");
+ return *Res.second;
}
void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) {
auto *Front = E->getMainOp();
- Instruction *LastInst = EntryToLastInstruction.lookup(E);
+ Instruction *LastInst = &getLastInstructionInBundle(E);
assert(LastInst && "Failed to find last instruction in bundle");
// If the instruction is PHI, set the insert point after all the PHIs.
bool IsPHI = isa<PHINode>(LastInst);
@@ -9685,7 +9684,7 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx) {
IRBuilder<>::InsertPointGuard Guard(Builder);
if (E->getOpcode() != Instruction::InsertElement &&
E->getOpcode() != Instruction::PHI) {
- Instruction *LastInst = EntryToLastInstruction.lookup(E);
+ Instruction *LastInst = &getLastInstructionInBundle(E);
assert(LastInst && "Failed to find last instruction in bundle");
Builder.SetInsertPoint(LastInst);
}
@@ -10704,18 +10703,9 @@ Value *BoUpSLP::vectorizeTree(
for (auto &BSIter : BlocksSchedules) {
scheduleBlock(BSIter.second.get());
}
-
- // Pre-gather last instructions.
- for (const std::unique_ptr<TreeEntry> &E : VectorizableTree) {
- if ((E->State == TreeEntry::NeedToGather &&
- (!E->getMainOp() || E->Idx > 0)) ||
- (E->State != TreeEntry::NeedToGather &&
- E->getOpcode() == Instruction::ExtractValue) ||
- E->getOpcode() == Instruction::InsertElement)
- continue;
- Instruction *LastInst = &getLastInstructionInBundle(E.get());
- EntryToLastInstruction.try_emplace(E.get(), LastInst);
- }
+ // Clean Entry-to-LastInstruction table. It can be affected after scheduling,
+ // need to rebuild it.
+ EntryToLastInstruction.clear();
Builder.SetInsertPoint(ReductionRoot ? ReductionRoot
: &F->getEntryBlock().front());
More information about the llvm-commits
mailing list