@@ -4315,7 +4315,7 @@ class BoUpSLP {
4315
4315
/// bundle being the last instruction in the program order during
4316
4316
/// vectorization process since the basic blocks are affected, need to
4317
4317
/// pre-gather them before.
4318
- DenseMap <const TreeEntry *, Instruction * > EntryToLastInstruction;
4318
+ SmallDenseMap <const TreeEntry *, WeakTrackingVH > EntryToLastInstruction;
4319
4319
4320
4320
/// List of gather nodes, depending on other gather/vector nodes, which should
4321
4321
/// be emitted after the vector instruction emission process to correctly
@@ -15976,9 +15976,10 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
15976
15976
}
15977
15977
15978
15978
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;
15982
15983
// Get the basic block this bundle is in. All instructions in the bundle
15983
15984
// should be in this block (except for extractelement-like instructions with
15984
15985
// constant indices or gathered loads).
@@ -16083,10 +16084,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
16083
16084
auto *I = dyn_cast_or_null<Instruction>(E->VectorizedValue);
16084
16085
if (!I)
16085
16086
I = &getLastInstructionInBundle(E);
16086
- if (Res->comesBefore(I))
16087
+ if (Res->getParent() == I->getParent() && Res-> comesBefore(I))
16087
16088
Res = I;
16088
16089
}
16089
16090
}
16091
+ EntryToLastInstruction.try_emplace(E, Res);
16090
16092
return *Res;
16091
16093
}
16092
16094
@@ -16095,6 +16097,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
16095
16097
E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() &&
16096
16098
E->getOpcode() == Instruction::Load) {
16097
16099
Res = FindFirstInst();
16100
+ EntryToLastInstruction.try_emplace(E, Res);
16098
16101
return *Res;
16099
16102
}
16100
16103
@@ -16141,6 +16144,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
16141
16144
Res = FindLastInst();
16142
16145
else
16143
16146
Res = FindFirstInst();
16147
+ EntryToLastInstruction.try_emplace(E, Res);
16144
16148
return *Res;
16145
16149
}
16146
16150
@@ -16151,6 +16155,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
16151
16155
if (Bundle) {
16152
16156
assert(!E->isGather() && "Gathered instructions should not be scheduled");
16153
16157
Res = Bundle->getBundle().back()->getInst();
16158
+ EntryToLastInstruction.try_emplace(E, Res);
16154
16159
return *Res;
16155
16160
}
16156
16161
@@ -16175,6 +16180,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
16175
16180
if (!Res)
16176
16181
Res = FindLastInst();
16177
16182
assert(Res && "Failed to find last instruction in bundle");
16183
+ EntryToLastInstruction.try_emplace(E, Res);
16178
16184
return *Res;
16179
16185
}
16180
16186
0 commit comments