Implement Transforms/InstCombine/store.ll:test2.
authorChris Lattner <sabre@nondot.org>
Fri, 26 May 2006 19:19:20 +0000 (19:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 26 May 2006 19:19:20 +0000 (19:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28503 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 1264e55497dade2076b87203fe9976b91bfbb60e..30a1de23aa49c83eae51667da2c0556b357e0682 100644 (file)
@@ -6833,8 +6833,22 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
       break;
     }
     
+    // If this is a load, we have to stop.  However, if the loaded value is from
+    // the pointer we're loading and is producing the pointer we're storing,
+    // then *this* store is dead (X = load P; store X -> P).
+    if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
+      if (LI == Val && LI->getOperand(0) == Ptr) {
+        EraseInstFromFunction(SI);
+        ++NumCombined;
+        return 0;
+      }
+      // Otherwise, this is a load from some other location.  Stores before it
+      // may not be dead.
+      break;
+    }
+    
     // Don't skip over loads or things that can modify memory.
-    if (BBI->mayWriteToMemory() || isa<LoadInst>(BBI))
+    if (BBI->mayWriteToMemory())
       break;
   }