From 6f62af6e64716a5add36531ccd1ffdfab7391224 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 30 Jul 2007 23:07:10 +0000 Subject: [PATCH] If loop can be unswitched again, then do it yourself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40609 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnswitch.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 4dba14d34ba..e8762dc96fb 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -70,12 +70,14 @@ namespace { SmallPtrSet UnswitchedVals; bool OptimizeForSize; + bool redoLoop; public: static char ID; // Pass ID, replacement for typeid LoopUnswitch(bool Os = false) : - LoopPass((intptr_t)&ID), OptimizeForSize(Os) {} + LoopPass((intptr_t)&ID), OptimizeForSize(Os), redoLoop(false) {} bool runOnLoop(Loop *L, LPPassManager &LPM); + bool processLoop(Loop *L); /// This transformation requires natural loop information & requires that /// loop preheaders be inserted into the CFG... @@ -152,11 +154,23 @@ static Value *FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed) { } bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) { - assert(L->isLCSSAForm()); LI = &getAnalysis(); LPM = &LPM_Ref; bool Changed = false; - + + do { + redoLoop = false; + Changed |= processLoop(L); + } while(redoLoop); + + return Changed; +} + +/// processLoop - Do actual work and unswitch loop if possible and profitable. +bool LoopUnswitch::processLoop(Loop *L) { + assert(L->isLCSSAForm()); + bool Changed = false; + // Loop over all of the basic blocks in the loop. If we find an interior // block that is branching on a loop-invariant condition, we can unswitch this // loop. @@ -576,7 +590,7 @@ void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond, OrigPH->getTerminator()->eraseFromParent(); // We need to reprocess this loop, it could be unswitched again. - LPM->redoLoop(L); + redoLoop = true; // Now that we know that the loop is never entered when this condition is a // particular value, rewrite the loop with this info. We know that this will @@ -740,7 +754,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, OldBR->eraseFromParent(); LoopProcessWorklist.push_back(NewLoop); - LPM->redoLoop(L); + redoLoop = true; // Now we rewrite the original code to know that the condition is true and the // new code to know that the condition is false.