Skip to content

Commit cc8ac51

Browse files
Don't bail out completely when unable to discover all phi-nodes
1 parent c951ec9 commit cc8ac51

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class InstCostVisitor : public InstVisitor<InstCostVisitor, Constant *> {
217217
Cost estimateSwitchInst(SwitchInst &I);
218218
Cost estimateBranchInst(BranchInst &I);
219219

220-
bool discoverTransitivelyIncomngValues(DenseSet<PHINode *> &PhiNodes,
220+
void discoverTransitivelyIncomngValues(DenseSet<PHINode *> &PhiNodes,
221221
PHINode *PN, unsigned Depth);
222222

223223
Constant *visitInstruction(Instruction &I) { return nullptr; }

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,38 +290,34 @@ Cost InstCostVisitor::estimateBranchInst(BranchInst &I) {
290290
// A depth limit is used to avoid extreme recurusion.
291291
// A max number of incoming phi values ensures that expensive searches
292292
// are avoided.
293-
//
294-
// Returns false if the discovery was aborted due to the above conditions.
295-
bool InstCostVisitor::discoverTransitivelyIncomngValues(
293+
void InstCostVisitor::discoverTransitivelyIncomngValues(
296294
DenseSet<PHINode *> &PHINodes, PHINode *PN, unsigned Depth) {
297295
if (Depth > MaxDiscoveryDepth) {
298296
LLVM_DEBUG(dbgs() << "FnSpecialization: Discover PHI nodes too deep ("
299297
<< Depth << ">" << MaxDiscoveryDepth << ")\n");
300-
return false;
298+
return;
301299
}
302300

303301
if (PN->getNumIncomingValues() > MaxIncomingPhiValues) {
304302
LLVM_DEBUG(
305303
dbgs() << "FnSpecialization: Discover PHI nodes has too many values ("
306304
<< PN->getNumIncomingValues() << ">" << MaxIncomingPhiValues
307305
<< ")\n");
308-
return false;
306+
return;
309307
}
310308

311309
// Already seen this, no more processing needed.
312310
if (!PHINodes.insert(PN).second)
313-
return true;
311+
return;
314312

315313
for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I) {
316314
Value *V = PN->getIncomingValue(I);
317315
if (auto *Phi = dyn_cast<PHINode>(V)) {
318316
if (Phi == PN || DeadBlocks.contains(PN->getIncomingBlock(I)))
319317
continue;
320-
if (!discoverTransitivelyIncomngValues(PHINodes, Phi, Depth + 1))
321-
return false;
318+
discoverTransitivelyIncomngValues(PHINodes, Phi, Depth + 1);
322319
}
323320
}
324-
return true;
325321
}
326322

327323
Constant *InstCostVisitor::visitPHINode(PHINode &I) {
@@ -378,8 +374,8 @@ Constant *InstCostVisitor::visitPHINode(PHINode &I) {
378374
// Try to see if we can collect a nest of transitive phis. Bail if
379375
// it's too complex.
380376
for (PHINode *Phi : UnknownIncomingValues)
381-
if (!discoverTransitivelyIncomngValues(TransitivePHIs, Phi, 1))
382-
return nullptr;
377+
discoverTransitivelyIncomngValues(TransitivePHIs, Phi, 1);
378+
383379

384380
// A nested set of PHINodes can be constantfolded if:
385381
// - It has a constant input.

0 commit comments

Comments
 (0)