[llvm] 1cb3fbc - Revert "[SLP][NFC]Improve compile-time by using map {TreeEntry *, Instruction *}"
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 17 14:57:20 PDT 2023
Author: Arthur Eubanks
Date: 2023-07-17T14:54:47-07:00
New Revision: 1cb3fbc713c4d6db2765b7d507c599b9df4a12b0
URL: https://github.com/llvm/llvm-project/commit/1cb3fbc713c4d6db2765b7d507c599b9df4a12b0
DIFF: https://github.com/llvm/llvm-project/commit/1cb3fbc713c4d6db2765b7d507c599b9df4a12b0.diff
LOG: Revert "[SLP][NFC]Improve compile-time by using map {TreeEntry *, Instruction *}"
This reverts commit 0d21b7cbdeb2f2eb5ef123a15099da0b651b24c0.
Causes broken IR, test case provided at
https://reviews.llvm.org/rG0d21b7cbdeb2f2eb5ef123a15099da0b651b24c0
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 d67aeaac5667af..b1727b31d537f0 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8994,9 +8994,6 @@ 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).
@@ -9011,7 +9008,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
isVectorLikeInstWithConstOps(I);
}));
- auto FindLastInst = [&]() {
+ auto &&FindLastInst = [E, Front, this, &BB]() {
Instruction *LastInst = Front;
for (Value *V : E->Scalars) {
auto *I = dyn_cast<Instruction>(V);
@@ -9047,7 +9044,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
return LastInst;
};
- auto FindFirstInst = [&]() {
+ auto &&FindFirstInst = [E, Front, this]() {
Instruction *FirstInst = Front;
for (Value *V : E->Scalars) {
auto *I = dyn_cast<Instruction>(V);
@@ -9087,6 +9084,7 @@ 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) {
@@ -9095,12 +9093,15 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
all_of(E->Scalars, [](Value *V) {
return !isVectorLikeInstWithConstOps(V) && isUsedOutsideBlock(V);
}))
- Res.second = FindLastInst();
+ InsertInst = FindLastInst();
else
- Res.second = FindFirstInst();
- return *Res.second;
+ InsertInst = FindFirstInst();
+ return *InsertInst;
}
+ // 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
@@ -9113,7 +9114,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
if (Bundle && Bundle->isPartOfBundle())
for (; Bundle; Bundle = Bundle->NextInBundle)
if (Bundle->OpValue == Bundle->Inst)
- Res.second = Bundle->Inst;
+ LastInst = Bundle->Inst;
}
// LastInst can still be null at this point if there's either not an entry
@@ -9134,15 +9135,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 (!Res.second)
- Res.second = FindLastInst();
- assert(Res.second && "Failed to find last instruction in bundle");
- return *Res.second;
+ if (!LastInst)
+ LastInst = FindLastInst();
+ assert(LastInst && "Failed to find last instruction in bundle");
+ return *LastInst;
}
void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) {
auto *Front = E->getMainOp();
- Instruction *LastInst = &getLastInstructionInBundle(E);
+ Instruction *LastInst = EntryToLastInstruction.lookup(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);
@@ -9663,7 +9664,7 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx) {
IRBuilder<>::InsertPointGuard Guard(Builder);
if (E->getOpcode() != Instruction::InsertElement &&
E->getOpcode() != Instruction::PHI) {
- Instruction *LastInst = &getLastInstructionInBundle(E);
+ Instruction *LastInst = EntryToLastInstruction.lookup(E);
assert(LastInst && "Failed to find last instruction in bundle");
Builder.SetInsertPoint(LastInst);
}
@@ -10683,6 +10684,18 @@ Value *BoUpSLP::vectorizeTree(
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);
+ }
+
Builder.SetInsertPoint(ReductionRoot ? ReductionRoot
: &F->getEntryBlock().front());
auto *VectorRoot = vectorizeTree(VectorizableTree[0].get());
More information about the llvm-commits
mailing list