[PATCH] D70016: [InstCombine] Don't use getFirstNonPHI in FoldIntegerTypedPHI

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 10:17:23 PST 2019


thegameg created this revision.
thegameg added reviewers: davidxl, wmi.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

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.


https://reviews.llvm.org/D70016

Files:
  llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -180,13 +180,14 @@
          "Not enough available ptr typed incoming values");
   PHINode *MatchingPtrPHI = nullptr;
   unsigned NumPhis = 0;
-  for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI());
-       II != EI; II++, NumPhis++) {
+  for (auto II = BB->begin(); II != BB->end(); II++, NumPhis++) {
     // FIXME: consider handling this in AggressiveInstCombine
+    PHINode *PtrPHI = dyn_cast<PHINode>(II);
+    if (!PtrPHI)
+      break;
     if (NumPhis > MaxNumPhis)
       return nullptr;
-    PHINode *PtrPHI = dyn_cast<PHINode>(II);
-    if (!PtrPHI || PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
+    if (PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
       continue;
     MatchingPtrPHI = PtrPHI;
     for (unsigned i = 0; i != PtrPHI->getNumIncomingValues(); ++i) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70016.228488.patch
Type: text/x-patch
Size: 1071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191108/bb1eedfb/attachment.bin>


More information about the llvm-commits mailing list