LICM does get dead instructions input to it. Instead of sinking them
authorChris Lattner <sabre@nondot.org>
Sun, 29 Aug 2010 18:22:25 +0000 (18:22 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Aug 2010 18:22:25 +0000 (18:22 +0000)
out of loops, just delete them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112451 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LICM.cpp
test/Transforms/LICM/sinking.ll

index 5f156dba7251c02125b7bd39f5b9880fe3d60cfa..aa842e3183b42bb525f910e958d507141dddd11a 100644 (file)
@@ -43,6 +43,7 @@
 #include "llvm/Analysis/AliasSetTracker.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Transforms/Utils/SSAUpdater.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/CommandLine.h"
@@ -299,7 +300,7 @@ void LICM::SinkRegion(DomTreeNode *N) {
   // If this subregion is not in the top level loop at all, exit.
   if (!CurLoop->contains(BB)) return;
 
-  // We are processing blocks in reverse dfo, so process children first...
+  // We are processing blocks in reverse dfo, so process children first.
   const std::vector<DomTreeNode*> &Children = N->getChildren();
   for (unsigned i = 0, e = Children.size(); i != e; ++i)
     SinkRegion(Children[i]);
@@ -310,6 +311,16 @@ void LICM::SinkRegion(DomTreeNode *N) {
 
   for (BasicBlock::iterator II = BB->end(); II != BB->begin(); ) {
     Instruction &I = *--II;
+    
+    // If the instruction is dead, we would try to sink it because it isn't used
+    // in the loop, instead, just delete it.
+    if (isInstructionTriviallyDead(&I)) {
+      ++II;
+      CurAST->deleteValue(&I);
+      I.eraseFromParent();
+      Changed = true;
+      continue;
+    }
 
     // Check to see if we can sink this instruction to the exit blocks
     // of the loop.  We can do this if the all users of the instruction are
index 11112eb74443fe40cf8ccd3c134159f695472754..68e4b64bf9bf6b6d1ee35dc1ba158c6261c18064 100644 (file)
@@ -233,3 +233,17 @@ Out:               ; preds = %Loop
 ; CHECK-NEXT:  ret i32 %tmp.6
 }
 
+; Should delete, not sink, dead instructions.
+define void @test11() {
+       br label %Loop
+Loop:
+       %dead = getelementptr %Ty* @X2, i64 0, i32 0
+       br i1 false, label %Loop, label %Out
+Out:
+       ret void
+; CHECK: @test11
+; CHECK:     Out:
+; CHECK-NEXT:  ret void
+}
+
+