diff options
author | Alexey Bataev <a.bataev@outlook.com> | 2025-05-14 10:58:53 -0700 |
---|---|---|
committer | Alexey Bataev <a.bataev@outlook.com> | 2025-05-14 11:19:54 -0700 |
commit | a05cf2927aab2494740853e6f4bd98591382e11c (patch) | |
tree | e7ef16a73086c8844ac845837691e7b794ded78b | |
parent | 6049db08fa5005c9535b22da0e07993395129f29 (diff) | |
download | llvm-a05cf2927aab2494740853e6f4bd98591382e11c.zip llvm-a05cf2927aab2494740853e6f4bd98591382e11c.tar.gz llvm-a05cf2927aab2494740853e6f4bd98591382e11c.tar.bz2 |
[SLP][NFC]Use WeakTrackVH instead of Instruction in EntryToLastInstruction
Use WEakTrackVH to prevent instability in the vectorizer.
Fixes #139729
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 45cf4e1..c63f806 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4315,7 +4315,7 @@ private: /// bundle being the last instruction in the program order during /// vectorization process since the basic blocks are affected, need to /// pre-gather them before. - DenseMap<const TreeEntry *, Instruction *> EntryToLastInstruction; + SmallDenseMap<const TreeEntry *, WeakTrackingVH> EntryToLastInstruction; /// List of gather nodes, depending on other gather/vector nodes, which should /// be emitted after the vector instruction emission process to correctly @@ -15976,9 +15976,10 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc, } Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { - auto &Res = EntryToLastInstruction.try_emplace(E).first->second; - if (Res) - return *Res; + auto It = EntryToLastInstruction.find(E); + if (It != EntryToLastInstruction.end()) + return *cast<Instruction>(It->second); + Instruction *Res = nullptr; // 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 indices or gathered loads). @@ -16083,10 +16084,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { auto *I = dyn_cast_or_null<Instruction>(E->VectorizedValue); if (!I) I = &getLastInstructionInBundle(E); - if (Res->comesBefore(I)) + if (Res->getParent() == I->getParent() && Res->comesBefore(I)) Res = I; } } + EntryToLastInstruction.try_emplace(E, Res); return *Res; } @@ -16095,6 +16097,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() && E->getOpcode() == Instruction::Load) { Res = FindFirstInst(); + EntryToLastInstruction.try_emplace(E, Res); return *Res; } @@ -16141,6 +16144,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { Res = FindLastInst(); else Res = FindFirstInst(); + EntryToLastInstruction.try_emplace(E, Res); return *Res; } @@ -16151,6 +16155,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { if (Bundle) { assert(!E->isGather() && "Gathered instructions should not be scheduled"); Res = Bundle->getBundle().back()->getInst(); + EntryToLastInstruction.try_emplace(E, Res); return *Res; } @@ -16175,6 +16180,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { if (!Res) Res = FindLastInst(); assert(Res && "Failed to find last instruction in bundle"); + EntryToLastInstruction.try_emplace(E, Res); return *Res; } |