diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index e1d89cb9109..dd66416e7fe 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -222,7 +222,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) { if (StoreInst *SI = dyn_cast(Inst)) { if (LoadInst *DepLoad = dyn_cast(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); diff --git a/test/Transforms/DeadStoreElimination/simple.ll b/test/Transforms/DeadStoreElimination/simple.ll index 6aba1d2125e..05e0d351dee 100644 --- a/test/Transforms/DeadStoreElimination/simple.ll +++ b/test/Transforms/DeadStoreElimination/simple.ll @@ -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 +}