[llvm-commits] [llvm] r86683 - in /llvm/trunk: lib/Transforms/Scalar/DeadStoreElimination.cpp test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll

Duncan Sands baldrick at free.fr
Tue Nov 10 05:49:51 PST 2009


Author: baldrick
Date: Tue Nov 10 07:49:50 2009
New Revision: 86683

URL: http://llvm.org/viewvc/llvm-project?rev=86683&view=rev
Log:
Teach DSE to eliminate useless trampolines.

Added:
    llvm/trunk/test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=86683&r1=86682&r2=86683&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Tue Nov 10 07:49:50 2009
@@ -87,13 +87,13 @@
     switch (II->getIntrinsicID()) {
     default: return false;
     case Intrinsic::memset: case Intrinsic::memmove: case Intrinsic::memcpy:
-    case Intrinsic::lifetime_end: return true;
+    case Intrinsic::init_trampoline: case Intrinsic::lifetime_end: return true;
     }
   }
   return false;
 }
 
-/// isElidable - If the memory this instruction and the memory it writes to is
+/// isElidable - If the value of this instruction and the memory it writes to is
 /// unused, may we delete this instrtction?
 static bool isElidable(Instruction *I) {
   assert(doesClobberMemory(I));
@@ -111,8 +111,15 @@
     return SI->getPointerOperand();
   if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I))
     return MI->getOperand(1);
-  assert(cast<IntrinsicInst>(I)->getIntrinsicID() == Intrinsic::lifetime_end);
-  return cast<IntrinsicInst>(I)->getOperand(2);
+  IntrinsicInst *II = cast<IntrinsicInst>(I);
+  switch (II->getIntrinsicID()) {
+    default:
+      assert(false && "Unexpected intrinsic!");
+    case Intrinsic::init_trampoline:
+      return II->getOperand(1);
+    case Intrinsic::lifetime_end:
+      return II->getOperand(2);
+  }
 }
 
 /// getStoreSize - Return the length in bytes of the write by the clobbering
@@ -129,8 +136,14 @@
     Len = MI->getLength();
   } else {
     IntrinsicInst *II = cast<IntrinsicInst>(I);
-    assert(II->getIntrinsicID() == Intrinsic::lifetime_end);
-    Len = II->getOperand(0);
+    switch (II->getIntrinsicID()) {
+      default:
+        assert(false && "Unexpected intrinsic!");
+      case Intrinsic::init_trampoline:
+        return -1u;
+      case Intrinsic::lifetime_end:
+        Len = II->getOperand(0);
+    }
   }
   if (ConstantInt *LenCI = dyn_cast<ConstantInt>(Len))
     if (!LenCI->isAllOnesValue())

Added: llvm/trunk/test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll?rev=86683&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll (added)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/2009-11-10-Trampoline.ll Tue Nov 10 07:49:50 2009
@@ -0,0 +1,16 @@
+; RUN: opt -S -dse < %s | FileCheck %s
+
+declare i8* @llvm.init.trampoline(i8*, i8*, i8*)
+
+declare void @f()
+
+define void @unused_trampoline() {
+; CHECK: @unused_trampoline
+	%storage = alloca [10 x i8], align 16		; <[10 x i8]*> [#uses=1]
+; CHECK-NOT: alloca
+	%cast = getelementptr [10 x i8]* %storage, i32 0, i32 0		; <i8*> [#uses=1]
+	%tramp = call i8* @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @f to i8*), i8* null )		; <i8*> [#uses=1]
+; CHECK-NOT: trampoline
+	ret void
+; CHECK: ret void
+}





More information about the llvm-commits mailing list