Skip to content

Commit a05cf29

Browse files
committed
[SLP][NFC]Use WeakTrackVH instead of Instruction in EntryToLastInstruction
Use WEakTrackVH to prevent instability in the vectorizer. Fixes #139729
1 parent 6049db0 commit a05cf29

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,7 +4315,7 @@ class BoUpSLP {
43154315
/// bundle being the last instruction in the program order during
43164316
/// vectorization process since the basic blocks are affected, need to
43174317
/// pre-gather them before.
4318-
DenseMap<const TreeEntry *, Instruction *> EntryToLastInstruction;
4318+
SmallDenseMap<const TreeEntry *, WeakTrackingVH> EntryToLastInstruction;
43194319

43204320
/// List of gather nodes, depending on other gather/vector nodes, which should
43214321
/// be emitted after the vector instruction emission process to correctly
@@ -15976,9 +15976,10 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
1597615976
}
1597715977

1597815978
Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
15979-
auto &Res = EntryToLastInstruction.try_emplace(E).first->second;
15980-
if (Res)
15981-
return *Res;
15979+
auto It = EntryToLastInstruction.find(E);
15980+
if (It != EntryToLastInstruction.end())
15981+
return *cast<Instruction>(It->second);
15982+
Instruction *Res = nullptr;
1598215983
// Get the basic block this bundle is in. All instructions in the bundle
1598315984
// should be in this block (except for extractelement-like instructions with
1598415985
// constant indices or gathered loads).
@@ -16083,10 +16084,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1608316084
auto *I = dyn_cast_or_null<Instruction>(E->VectorizedValue);
1608416085
if (!I)
1608516086
I = &getLastInstructionInBundle(E);
16086-
if (Res->comesBefore(I))
16087+
if (Res->getParent() == I->getParent() && Res->comesBefore(I))
1608716088
Res = I;
1608816089
}
1608916090
}
16091+
EntryToLastInstruction.try_emplace(E, Res);
1609016092
return *Res;
1609116093
}
1609216094

@@ -16095,6 +16097,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1609516097
E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() &&
1609616098
E->getOpcode() == Instruction::Load) {
1609716099
Res = FindFirstInst();
16100+
EntryToLastInstruction.try_emplace(E, Res);
1609816101
return *Res;
1609916102
}
1610016103

@@ -16141,6 +16144,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1614116144
Res = FindLastInst();
1614216145
else
1614316146
Res = FindFirstInst();
16147+
EntryToLastInstruction.try_emplace(E, Res);
1614416148
return *Res;
1614516149
}
1614616150

@@ -16151,6 +16155,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1615116155
if (Bundle) {
1615216156
assert(!E->isGather() && "Gathered instructions should not be scheduled");
1615316157
Res = Bundle->getBundle().back()->getInst();
16158+
EntryToLastInstruction.try_emplace(E, Res);
1615416159
return *Res;
1615516160
}
1615616161

@@ -16175,6 +16180,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
1617516180
if (!Res)
1617616181
Res = FindLastInst();
1617716182
assert(Res && "Failed to find last instruction in bundle");
16183+
EntryToLastInstruction.try_emplace(E, Res);
1617816184
return *Res;
1617916185
}
1618016186

0 commit comments

Comments
 (0)