my previous patch would cause us to start deleting some volatile
authorChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2010 00:12:39 +0000 (00:12 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 30 Nov 2010 00:12:39 +0000 (00:12 +0000)
stores, fix and add a testcase.

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

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

index e1d89cb910931feaa954146041356dc0320a7a65..dd66416e7fe29cf7f87b84ae2f6e11d639da85d7 100644 (file)
@@ -222,7 +222,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
     if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
       if (LoadInst *DepLoad = dyn_cast<LoadInst>(InstDep.getInst())) {
         if (SI->getPointerOperand() == DepLoad->getPointerOperand() &&
-            SI->getOperand(0) == DepLoad) {
+            SI->getOperand(0) == DepLoad && !SI->isVolatile()) {
           // DeleteDeadInstruction can delete the current instruction.  Save BBI
           // in case we need it.
           WeakVH NextInst(BBI);
index 6aba1d2125e27a34a9633ee3137ad613e59a1264..05e0d351dee9188b94f22b0beacb2f22874ed183 100644 (file)
@@ -34,3 +34,23 @@ define i32 @test3(i32* %g_addr) nounwind {
   %tmp3 = load i32* @g, align 4
   ret i32 %tmp3
 }
+
+
+define void @test4(i32* %Q) {
+        %a = load i32* %Q
+        volatile store i32 %a, i32* %Q
+        ret void
+; CHECK: @test4
+; CHECK-NEXT: load i32
+; CHECK-NEXT: volatile store
+; CHECK-NEXT: ret void
+}
+
+define void @test5(i32* %Q) {
+        %a = volatile load i32* %Q
+        store i32 %a, i32* %Q
+        ret void
+; CHECK: @test5
+; CHECK-NEXT: volatile load
+; CHECK-NEXT: ret void
+}