Skip to content

Commit fe46360

Browse files
david-armjoaosaffran
authored andcommitted
[LoopVectorize] Make collectInLoopReductions more efficient (llvm#126769)
We call collectInLoopReductions in multiple places asking the same question with exactly the same answer. For example, this was being called from a loop in calculateRegisterUsage and this patch hoists the call out to above the loop. In addition I've changed collectInLoopReductions so that it bails out if we've already built up a list.
1 parent d344d5e commit fe46360

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5260,6 +5260,8 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<ElementCount> VFs) {
52605260
return TTICapture.getRegUsageForType(VectorType::get(Ty, VF));
52615261
};
52625262

5263+
collectInLoopReductions();
5264+
52635265
for (unsigned int Idx = 0, Sz = IdxToInstr.size(); Idx < Sz; ++Idx) {
52645266
Instruction *I = IdxToInstr[Idx];
52655267

@@ -5276,8 +5278,6 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<ElementCount> VFs) {
52765278
if (ValuesToIgnore.count(I))
52775279
continue;
52785280

5279-
collectInLoopReductions();
5280-
52815281
// For each VF find the maximum usage of registers.
52825282
for (unsigned J = 0, E = VFs.size(); J < E; ++J) {
52835283
// Count the number of registers used, per register class, given all open
@@ -7008,6 +7008,10 @@ void LoopVectorizationCostModel::collectValuesToIgnore() {
70087008
}
70097009

70107010
void LoopVectorizationCostModel::collectInLoopReductions() {
7011+
// Avoid duplicating work finding in-loop reductions.
7012+
if (!InLoopReductions.empty())
7013+
return;
7014+
70117015
for (const auto &Reduction : Legal->getReductionVars()) {
70127016
PHINode *Phi = Reduction.first;
70137017
const RecurrenceDescriptor &RdxDesc = Reduction.second;

0 commit comments

Comments
 (0)