[PATCH] Teaching loop simplify to preserve LCSSA

Dinesh Dwivedi dinesh.d at samsung.com
Thu Mar 6 07:53:04 PST 2014


Hi chandlerc,

As Chandler has mentioned at http://llvm.org/bugs/show_bug.cgi?id=18616#c4, it is loop simplify which destroy LCSSA. I tried to find out what destroys LCSSA and found that it is 'removePredecessor()' calls at the end of 'simplifyOneLoop()'.

removePredecessor() deletes all PHIs with one incoming value, which in some cases destroy LCSSA. Calling removePredecessor() call with 'DontDeleteUselessPHIs = true' preserves LSCCA, atleast in case of the test-cases attached with PR18616.

With this fix, we can remove bulky formLCSSARecursively() call from LoopUnroll.


http://llvm-reviews.chandlerc.com/D2986

Files:
  lib/Transforms/Utils/LoopSimplify.cpp
  lib/Transforms/Utils/LoopUnroll.cpp

Index: lib/Transforms/Utils/LoopSimplify.cpp
===================================================================
--- lib/Transforms/Utils/LoopSimplify.cpp
+++ lib/Transforms/Utils/LoopSimplify.cpp
@@ -697,8 +697,8 @@
       }
       DT->eraseNode(ExitingBlock);
 
-      BI->getSuccessor(0)->removePredecessor(ExitingBlock);
-      BI->getSuccessor(1)->removePredecessor(ExitingBlock);
+      BI->getSuccessor(0)->removePredecessor(ExitingBlock, true);
+      BI->getSuccessor(1)->removePredecessor(ExitingBlock, true);
       ExitingBlock->eraseFromParent();
     }
   }
Index: lib/Transforms/Utils/LoopUnroll.cpp
===================================================================
--- lib/Transforms/Utils/LoopUnroll.cpp
+++ lib/Transforms/Utils/LoopUnroll.cpp
@@ -469,9 +469,8 @@
     if (!OuterL && !CompletelyUnroll)
       OuterL = L;
     if (OuterL) {
-      ScalarEvolution *SE = PP->getAnalysisIfAvailable<ScalarEvolution>();
-      simplifyLoop(OuterL, DT, LI, PP, /*AliasAnalysis*/ 0, SE);
-      formLCSSARecursively(*OuterL, *DT, SE);
+      simplifyLoop(OuterL, DT, LI, PP, /*AliasAnalysis*/ 0,
+                   PP->getAnalysisIfAvailable<ScalarEvolution>());
     }
   }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2986.1.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140306/6a6d9723/attachment.bin>


More information about the llvm-commits mailing list