Move the GET_SIDE_EFFECT_INFO logic from isInstructionTriviallyDead
authorDan Gohman <gohman@apple.com>
Thu, 26 Jul 2007 16:06:08 +0000 (16:06 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 26 Jul 2007 16:06:08 +0000 (16:06 +0000)
to Instruction::mayWriteToMemory, fixing a FIXME, and helping
various places that call mayWriteToMemory directly.

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

lib/Transforms/Utils/Local.cpp
lib/VMCore/Instruction.cpp

index 5e2d2375cca36c0065db584bcbdff701d432cf6e..187ebdc79793c780e7ec751cb636bb379983a706 100644 (file)
@@ -175,13 +175,6 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
 
   if (!I->mayWriteToMemory()) return true;
 
-  if (CallInst *CI = dyn_cast<CallInst>(I))
-    if (Function *F = CI->getCalledFunction()) {
-      unsigned IntrinsicID = F->getIntrinsicID();
-#define GET_SIDE_EFFECT_INFO
-#include "llvm/Intrinsics.gen"
-#undef GET_SIDE_EFFECT_INFO
-    }
   return false;
 }
 
index feff59dff9f12483e9a8285b83d843260cbdd29f..a3687530de9b69a69e251fda3da08f145f39f4ad 100644 (file)
@@ -197,6 +197,15 @@ bool Instruction::isSameOperationAs(Instruction *I) const {
   return true;
 }
 
+// IntrinsicOnlyReadsMemory - Return true if the specified intrinsic doesn't
+// have any side-effects or if it only reads memory.
+static bool IntrinsicOnlyReadsMemory(unsigned IntrinsicID) {
+#define GET_SIDE_EFFECT_INFO
+#include "llvm/Intrinsics.gen"
+#undef GET_SIDE_EFFECT_INFO
+  return false;
+}
+
 /// mayWriteToMemory - Return true if this instruction may modify memory.
 ///
 bool Instruction::mayWriteToMemory() const {
@@ -208,11 +217,10 @@ bool Instruction::mayWriteToMemory() const {
   case Instruction::VAArg:
     return true;
   case Instruction::Call:
-    //if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
+    if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(this)) {
       // If the intrinsic doesn't write memory, it is safe.
-      // FIXME: this is obviously supposed to determine which  intrinsics 
-      // don't write to memory, but hasn't been implemented yet.
-    //}
+      return !IntrinsicOnlyReadsMemory(II->getIntrinsicID());
+    }
     return true;
   case Instruction::Load:
     return cast<LoadInst>(this)->isVolatile();