Don't trivially delete unused calls to llvm.invariant.start. This allows
authorDuncan Sands <baldrick@free.fr>
Wed, 11 Nov 2009 15:34:13 +0000 (15:34 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 11 Nov 2009 15:34:13 +0000 (15:34 +0000)
llvm.invariant.start to be used without necessarily being paired with a call
to llvm.invariant.end.  If you run the entire optimization pipeline then such
calls are in fact deleted (adce does it), but that's actually a good thing since
we probably do want them to be zapped late in the game.  There should really be
an integration test that checks that the llvm.invariant.start call lasts long
enough that all passes that do interesting things with it get to do their stuff
before it is deleted.  But since no passes do anything interesting with it yet
this will have to wait for later.

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

include/llvm/IntrinsicInst.h
lib/Transforms/Utils/Local.cpp
test/Transforms/InstCombine/invariant.ll [new file with mode: 0644]

index 6a8f3763926139fd0854a77b09380f31d3b72ac3..1e1dca2ebab7c997fd0a02c93c07bf4b560ef1ae 100644 (file)
@@ -320,6 +320,28 @@ namespace llvm {
     }
   };
   
+  /// MemoryUseIntrinsic - This is the common base class for the memory use
+  /// marker intrinsics.
+  ///
+  struct MemoryUseIntrinsic : public IntrinsicInst {
+
+    // Methods for support type inquiry through isa, cast, and dyn_cast:
+    static inline bool classof(const MemoryUseIntrinsic *) { return true; }
+    static inline bool classof(const IntrinsicInst *I) {
+      switch (I->getIntrinsicID()) {
+      case Intrinsic::lifetime_start:
+      case Intrinsic::lifetime_end:
+      case Intrinsic::invariant_start:
+      case Intrinsic::invariant_end:
+        return true;
+      default: return false;
+      }
+    }
+    static inline bool classof(const Value *V) {
+      return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
+    }
+  };
+
 }
 
 #endif
index 0167ea0bcb24a2c00815c6aa2f3f9c084812db77..aef0f5f03c2770a7253997d8d2da5d8cc5325251 100644 (file)
@@ -252,6 +252,9 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
   // We don't want debug info removed by anything this general.
   if (isa<DbgInfoIntrinsic>(I)) return false;
 
+  // Likewise for memory use markers.
+  if (isa<MemoryUseIntrinsic>(I)) return false;
+
   if (!I->mayHaveSideEffects()) return true;
 
   // Special case intrinsics that "may have side effects" but can be deleted
diff --git a/test/Transforms/InstCombine/invariant.ll b/test/Transforms/InstCombine/invariant.ll
new file mode 100644 (file)
index 0000000..c67ad33
--- /dev/null
@@ -0,0 +1,16 @@
+; Test to make sure unused llvm.invariant.start calls are not trivially eliminated
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare void @g(i8*)
+
+declare { }* @llvm.invariant.start(i64, i8* nocapture) nounwind readonly
+
+define i8 @f() {
+  %a = alloca i8                                  ; <i8*> [#uses=4]
+  store i8 0, i8* %a
+  %i = call { }* @llvm.invariant.start(i64 1, i8* %a) ; <{ }*> [#uses=0]
+  ; CHECK: call { }* @llvm.invariant.start
+  call void @g(i8* %a)
+  %r = load i8* %a                                ; <i8> [#uses=1]
+  ret i8 %r
+}