Skip to content

Commit 5214dbb

Browse files
committed
[InstCombine] Don't use getFirstNonPHI in FoldIntegerTypedPHI
getFirstNonPHI iterates over all the instructions in a block until it finds a non-PHI. Then, the loop starts from the beginning of the block and goes through all the instructions until it reaches the instruction found by getFirstNonPHI. Instead of doing that, just stop when a non-PHI is found. This reduces the compile-time of a test case discussed in https://reviews.llvm.org/D47023 by 13x. Not entirely sure how to come up with a test case for this since it's a compile time issue that would significantly slow down running the tests. Differential Revision: https://reviews.llvm.org/D70016 (cherry picked from commit a4c76be) rdar://47501426
1 parent e615579 commit 5214dbb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,14 @@ Instruction *InstCombiner::FoldIntegerTypedPHI(PHINode &PN) {
180180
"Not enough available ptr typed incoming values");
181181
PHINode *MatchingPtrPHI = nullptr;
182182
unsigned NumPhis = 0;
183-
for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI());
184-
II != EI; II++, NumPhis++) {
183+
for (auto II = BB->begin(); II != BB->end(); II++, NumPhis++) {
185184
// FIXME: consider handling this in AggressiveInstCombine
185+
PHINode *PtrPHI = dyn_cast<PHINode>(II);
186+
if (!PtrPHI)
187+
break;
186188
if (NumPhis > MaxNumPhis)
187189
return nullptr;
188-
PHINode *PtrPHI = dyn_cast<PHINode>(II);
189-
if (!PtrPHI || PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
190+
if (PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
190191
continue;
191192
MatchingPtrPHI = PtrPHI;
192193
for (unsigned i = 0; i != PtrPHI->getNumIncomingValues(); ++i) {

0 commit comments

Comments
 (0)