Skip to content

Commit 5ae324d

Browse files
nikickbluck
authored andcommitted
[SROA] Avoid expensive isComplete() call (NFC)
llvm#83381 introduced a call to PHINode::isComplete() in Mem2Reg, which is O(n^2) in the number of predecessors, resulting in pathological compile-time regressions for cases with many predecessors. Remove the isComplete() check and instead cache the attribute lookup, to only perform it once per function. Actually setting the FMF flag is cheap.
1 parent e827cc1 commit 5ae324d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ struct PromoteMem2Reg {
393393
/// Lazily compute the number of predecessors a block has.
394394
DenseMap<const BasicBlock *, unsigned> BBNumPreds;
395395

396+
/// Whether the function has the no-signed-zeros-fp-math attribute set.
397+
bool NoSignedZeros = false;
398+
396399
public:
397400
PromoteMem2Reg(ArrayRef<AllocaInst *> Allocas, DominatorTree &DT,
398401
AssumptionCache *AC)
@@ -740,6 +743,8 @@ void PromoteMem2Reg::run() {
740743
LargeBlockInfo LBI;
741744
ForwardIDFCalculator IDF(DT);
742745

746+
NoSignedZeros = F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool();
747+
743748
for (unsigned AllocaNum = 0; AllocaNum != Allocas.size(); ++AllocaNum) {
744749
AllocaInst *AI = Allocas[AllocaNum];
745750

@@ -1128,10 +1133,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
11281133
// on the phi node generated at this stage, fabs folding does not
11291134
// happen. So, we try to infer nsz flag from the function attributes to
11301135
// enable this fabs folding.
1131-
if (APN->isComplete() && isa<FPMathOperator>(APN) &&
1132-
BB->getParent()
1133-
->getFnAttribute("no-signed-zeros-fp-math")
1134-
.getValueAsBool())
1136+
if (isa<FPMathOperator>(APN) && NoSignedZeros)
11351137
APN->setHasNoSignedZeros(true);
11361138

11371139
// The currently active variable for this block is now the PHI.

0 commit comments

Comments
 (0)