Skip to content

Commit 2dbc6d4

Browse files
committed
[SLP][NFC]Assert total number of scalar uses not less than number of scalar uses, NFC.
1 parent c664d7d commit 2dbc6d4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10842,17 +10842,22 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
1084210842
// Leave the scalar instructions as is if they are cheaper than extracts.
1084310843
if (Entry->Idx != 0 || Entry->getOpcode() == Instruction::GetElementPtr ||
1084410844
Entry->getOpcode() == Instruction::Load) {
10845+
// Checks if the user of the external scalar is phi in loop body.
10846+
auto IsPhiInLoop = [&](const ExternalUser &U) {
10847+
if (auto *Phi = dyn_cast_if_present<PHINode>(U.User)) {
10848+
auto *I = cast<Instruction>(U.Scalar);
10849+
const Loop *L = LI->getLoopFor(Phi->getParent());
10850+
return L && (Phi->getParent() == I->getParent() ||
10851+
L == LI->getLoopFor(I->getParent()));
10852+
}
10853+
return false;
10854+
};
1084510855
if (!ValueToExtUses) {
1084610856
ValueToExtUses.emplace();
1084710857
for_each(enumerate(ExternalUses), [&](const auto &P) {
1084810858
// Ignore phis in loops.
10849-
if (auto *Phi = dyn_cast_if_present<PHINode>(P.value().User)) {
10850-
auto *I = cast<Instruction>(P.value().Scalar);
10851-
const Loop *L = LI->getLoopFor(Phi->getParent());
10852-
if (L && (Phi->getParent() == I->getParent() ||
10853-
L == LI->getLoopFor(I->getParent())))
10854-
return;
10855-
}
10859+
if (IsPhiInLoop(P.value()))
10860+
return;
1085610861

1085710862
ValueToExtUses->try_emplace(P.value().Scalar, P.index());
1085810863
});
@@ -10903,8 +10908,12 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
1090310908
return ValueToExtUses->contains(V);
1090410909
});
1090510910
auto It = ExtractsCount.find(Entry);
10906-
if (It != ExtractsCount.end())
10911+
if (It != ExtractsCount.end()) {
10912+
assert(ScalarUsesCount >= It->getSecond().size() &&
10913+
"Expected total number of external uses not less than "
10914+
"number of scalar uses.");
1090710915
ScalarUsesCount -= It->getSecond().size();
10916+
}
1090810917
// Keep original scalar if number of externally used instructions in
1090910918
// the same entry is not power of 2. It may help to do some extra
1091010919
// vectorization for now.
@@ -10920,7 +10929,8 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) {
1092010929
}
1092110930
});
1092210931
ExtraCost = ScalarCost;
10923-
ExtractsCount[Entry].insert(Inst);
10932+
if (!IsPhiInLoop(EU))
10933+
ExtractsCount[Entry].insert(Inst);
1092410934
}
1092510935
}
1092610936
}

0 commit comments

Comments
 (0)