Skip to content

Commit 5850c44

Browse files
authored
[InstCombine] Improve foldDeadPhiWeb compile time (#158057)
The foldDeadPhiWeb function identifies and removes small dead PHI webs, it bails out if the web size exceeds threshold (16). In the current implementation, when there is a phi node has large number of users that most of them are phi nodes, we still push them on the `Stack` even if the number of phi nodes user exceeds the threshold. This patch checks the early stop condition when we push an unvisited phi node on the `Stack`. With this change, the wall duration of total instcombine pass decreased from 523,649.276 ms to 208,687.042 ms in an our internal case.
1 parent fef88d2 commit 5850c44

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ bool InstCombinerImpl::foldDeadPhiWeb(PHINode &PN) {
6060
SmallVector<PHINode *, 16> Stack;
6161
SmallPtrSet<PHINode *, 16> Visited;
6262
Stack.push_back(&PN);
63+
Visited.insert(&PN);
6364
while (!Stack.empty()) {
6465
PHINode *Phi = Stack.pop_back_val();
65-
if (!Visited.insert(Phi).second)
66-
continue;
67-
// Early stop if the set of PHIs is large
68-
if (Visited.size() == 16)
69-
return false;
7066
for (User *Use : Phi->users()) {
71-
if (PHINode *PhiUse = dyn_cast<PHINode>(Use))
67+
if (PHINode *PhiUse = dyn_cast<PHINode>(Use)) {
68+
if (!Visited.insert(PhiUse).second)
69+
continue;
70+
// Early stop if the set of PHIs is large
71+
if (Visited.size() >= 16)
72+
return false;
7273
Stack.push_back(PhiUse);
73-
else
74+
} else
7475
return false;
7576
}
7677
}

0 commit comments

Comments
 (0)