[llvm] r284303 - [SimplifyCFG] Use the error checking provided by getPrevNode.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 15 06:15:06 PDT 2016


Author: d0k
Date: Sat Oct 15 08:15:05 2016
New Revision: 284303

URL: http://llvm.org/viewvc/llvm-project?rev=284303&view=rev
Log:
[SimplifyCFG] Use the error checking provided by getPrevNode.

BasicBlock::size is O(insts), making this loop O(blocks*insts), which
can be really slow on generated code. getPrevNode already checks if
we're at the beginning of the block and returns nullptr if so, just use
that instead. No functionality change intended.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=284303&r1=284302&r2=284303&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sat Oct 15 08:15:05 2016
@@ -1584,12 +1584,15 @@ namespace {
       Fail = false;
       Insts.clear();
       for (auto *BB : Blocks) {
-        if (BB->size() <= 1) {
-          // Block wasn't big enough
-          Fail = true;
-          return;
+        if (Instruction *Terminator = BB->getTerminator()) {
+          if (Instruction *LastNonTerminator = Terminator->getPrevNode()) {
+            Insts.push_back(LastNonTerminator);
+            continue;
+          }
         }
-        Insts.push_back(BB->getTerminator()->getPrevNode());
+        // Block wasn't big enough.
+        Fail = true;
+        return;
       }
     }
 
@@ -1601,11 +1604,12 @@ namespace {
       if (Fail)
         return;
       for (auto *&Inst : Insts) {
-        if (Inst == &Inst->getParent()->front()) {
+        Inst = Inst->getPrevNode();
+        // Already at beginning of block.
+        if (!Inst) {
           Fail = true;
           return;
         }
-        Inst = Inst->getPrevNode();
       }
     }
 




More information about the llvm-commits mailing list