@@ -5514,6 +5514,7 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
5514
5514
5515
5515
void BoUpSLP::buildExternalUses(
5516
5516
const ExtraValueToDebugLocsMap &ExternallyUsedValues) {
5517
+ DenseMap<Value *, unsigned> ScalarToExtUses;
5517
5518
// Collect the values that we need to extract from the tree.
5518
5519
for (auto &TEPtr : VectorizableTree) {
5519
5520
TreeEntry *Entry = TEPtr.get();
@@ -5527,13 +5528,18 @@ void BoUpSLP::buildExternalUses(
5527
5528
Value *Scalar = Entry->Scalars[Lane];
5528
5529
if (!isa<Instruction>(Scalar))
5529
5530
continue;
5530
- int FoundLane = Entry->findLaneForValue(Scalar);
5531
+ // All uses must be replaced already? No need to do it again.
5532
+ auto It = ScalarToExtUses.find(Scalar);
5533
+ if (It != ScalarToExtUses.end() && !ExternalUses[It->second].User)
5534
+ continue;
5531
5535
5532
5536
// Check if the scalar is externally used as an extra arg.
5533
5537
const auto *ExtI = ExternallyUsedValues.find(Scalar);
5534
5538
if (ExtI != ExternallyUsedValues.end()) {
5539
+ int FoundLane = Entry->findLaneForValue(Scalar);
5535
5540
LLVM_DEBUG(dbgs() << "SLP: Need to extract: Extra arg from lane "
5536
- << Lane << " from " << *Scalar << ".\n");
5541
+ << FoundLane << " from " << *Scalar << ".\n");
5542
+ ScalarToExtUses.try_emplace(Scalar, ExternalUses.size());
5537
5543
ExternalUses.emplace_back(Scalar, nullptr, FoundLane);
5538
5544
}
5539
5545
for (User *U : Scalar->users()) {
@@ -5561,12 +5567,20 @@ void BoUpSLP::buildExternalUses(
5561
5567
continue;
5562
5568
}
5563
5569
U = nullptr;
5570
+ if (It != ScalarToExtUses.end()) {
5571
+ ExternalUses[It->second].User = nullptr;
5572
+ break;
5573
+ }
5564
5574
}
5565
5575
5576
+ int FoundLane = Entry->findLaneForValue(Scalar);
5566
5577
LLVM_DEBUG(dbgs() << "SLP: Need to extract:" << *UserInst
5567
- << " from lane " << Lane << " from " << *Scalar
5578
+ << " from lane " << FoundLane << " from " << *Scalar
5568
5579
<< ".\n");
5580
+ It = ScalarToExtUses.try_emplace(Scalar, ExternalUses.size()).first;
5569
5581
ExternalUses.emplace_back(Scalar, U, FoundLane);
5582
+ if (!U)
5583
+ break;
5570
5584
}
5571
5585
}
5572
5586
}
0 commit comments