fix PR8677, patch by Jakub Staszak!
authorChris Lattner <sabre@nondot.org>
Mon, 29 Nov 2010 21:59:31 +0000 (21:59 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 29 Nov 2010 21:59:31 +0000 (21:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120325 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/DeadStoreElimination.cpp
test/Transforms/DeadStoreElimination/simple.ll

index 02df1031e6046634b9156170898768c76ac3c9ca..4540ccce8c6550ebb8bb8a92aecfc08625d8f007 100644 (file)
@@ -235,8 +235,10 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
                                                 &BB);
       }
         
-      // If not a definite must-alias dependency, ignore it.
-      if (!InstDep.isDef())
+      // If not a definite must-alias store dependency, ignore it.  If this is a
+      // load from the same pointer, we don't want to transform load+store into
+      // a noop.
+      if (!InstDep.isDef() || !isa<StoreInst>(InstDep.getInst()))
         continue;
     }
     
index 0a16603f55d5503d88b2940b2c12cd765687117b..ab0ef7b7eb21102c785f93ff14e99d2304879dd4 100644 (file)
@@ -20,3 +20,17 @@ define void @test2(i32 *%p, i32 *%q) {
 ; CHECK: @test2
 ; CHECK-NEXT: store i32 20
 }
+
+
+; PR8677
+@g = global i32 1
+
+define i32 @test3(i32* %g_addr) nounwind {
+; CHECK: @test3
+; CHEcK: load i32* %g_addr
+  %g_value = load i32* %g_addr, align 4
+  store i32 -1, i32* @g, align 4
+  store i32 %g_value, i32* %g_addr, align 4
+  %tmp3 = load i32* @g, align 4
+  ret i32 %tmp3
+}