[llvm] r292282 - [LoopDeletion] (cleanup, NFC) Use the dedicated helper to get a single

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 14:28:52 PST 2017


Author: chandlerc
Date: Tue Jan 17 16:28:52 2017
New Revision: 292282

URL: http://llvm.org/viewvc/llvm-project?rev=292282&view=rev
Log:
[LoopDeletion] (cleanup, NFC) Use the dedicated helper to get a single
unique exit block if available rather than rolling it ourselves.

This is a little disappointing because that helper doesn't do anything
clever to short-circuit the (surprisingly expensive) computation of all
exit blocks. What's worse is that the way we compute this is hopelessly,
hilariously inefficient. We're literally computing the same information
two different ways and multiple times each way:
- hasDedicatedExits computes the exit block set and then looks at the
  predecessors of each
- getExitingBlocks computes the set of loop blocks which have exiting
  successors
- getUniqueExitBlock(s) computes the set of non-loop blocks reached from
  loop blocks (sound familiar?)

Anyways, at some point we should clean all of this up in the LoopInfo
API, but for now just simplifying the user I'm about to touch.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp?rev=292282&r1=292281&r2=292282&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopDeletion.cpp Tue Jan 17 16:28:52 2017
@@ -126,18 +126,14 @@ static bool deleteLoopIfDead(Loop *L, Do
   SmallVector<BasicBlock *, 4> ExitingBlocks;
   L->getExitingBlocks(ExitingBlocks);
 
-  SmallVector<BasicBlock *, 4> ExitBlocks;
-  L->getUniqueExitBlocks(ExitBlocks);
-
   // We require that the loop only have a single exit block.  Otherwise, we'd
   // be in the situation of needing to be able to solve statically which exit
   // block will be branched to, or trying to preserve the branching logic in
   // a loop invariant manner.
-  if (ExitBlocks.size() != 1)
+  BasicBlock *ExitBlock = L->getUniqueExitBlock();
+  if (!ExitBlock)
     return false;
 
-  BasicBlock *ExitBlock = ExitBlocks[0];
-
   // Finally, we have to check that the loop really is dead.
   bool Changed = false;
   if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader))




More information about the llvm-commits mailing list