Lifetime intrinsics on undef are dead.
authorNick Lewycky <nicholas@mxc.ca>
Tue, 2 Aug 2011 21:19:27 +0000 (21:19 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Tue, 2 Aug 2011 21:19:27 +0000 (21:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136722 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/Local.cpp
test/Transforms/InstCombine/deadcode.ll

index 2d43e3773efc1e7aa2ed83ff5a3155245046da99..60dc15d642510f2d1c596481b1b2691238f244aa 100644 (file)
@@ -229,10 +229,10 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
   // We don't want debug info removed by anything this general, unless
   // debug info is empty.
   if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) {
-    if (DDI->getAddress()) 
+    if (DDI->getAddress())
       return false;
     return true;
-  } 
+  }
   if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(I)) {
     if (DVI->getValue())
       return false;
@@ -243,10 +243,16 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
 
   // Special case intrinsics that "may have side effects" but can be deleted
   // when dead.
-  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I))
+  if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
     // Safe to delete llvm.stacksave if dead.
     if (II->getIntrinsicID() == Intrinsic::stacksave)
       return true;
+
+    // Lifetime intrinsics are dead when their right-hand is undef.
+    if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
+        II->getIntrinsicID() == Intrinsic::lifetime_end)
+      return isa<UndefValue>(II->getArgOperand(1));
+  }
   return false;
 }
 
index 52af0ef4e8d4e15212c9751e0c22085135872409..7c7f1abc0ca662211aefd272227d8815ce2a9a3f 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: opt < %s -instcombine -S | grep {ret i32 %A}
-; RUN: opt < %s -die -S | not grep call.*llvm.stacksave
+; RUN: opt < %s -die -S | not grep call.*llvm
 
 define i32 @test(i32 %A) {
        %X = or i1 false, false         
@@ -22,3 +22,12 @@ define i32* @test2(i32 %width) {
 
 declare i8* @llvm.stacksave()
 
+declare void @llvm.lifetime.start(i64, i8*)
+declare void @llvm.lifetime.end(i64, i8*)
+
+define void @test3() {
+  call void @llvm.lifetime.start(i64 -1, i8* undef)
+  call void @llvm.lifetime.end(i64 -1, i8* undef)
+  ret void
+}
+