From 00acf97feb2cba053a07505dfad9116ad09aae7a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 28 Apr 2008 19:51:27 +0000 Subject: [PATCH] Fix DSE to not eliminate volatile loads with no uses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50370 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/DeadStoreElimination.cpp | 6 +++--- test/Transforms/DeadStoreElimination/volatile-load.ll | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 test/Transforms/DeadStoreElimination/volatile-load.ll diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index f9d1205ada5..89afa911e75 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -326,9 +326,9 @@ bool DSE::handleEndBlock(BasicBlock& BB, // If we encounter a use of the pointer, it is no longer considered dead if (LoadInst* L = dyn_cast(BBI)) { - // However, if this load is unused, we can go ahead and remove it, and - // not have to worry about it making our pointer undead! - if (L->use_empty()) { + // However, if this load is unused and not volatile, we can go ahead and remove it, + // and not have to worry about it making our pointer undead! + if (L->use_empty() && !L->isVolatile()) { MD.removeInstruction(L); // DCE instructions only used to calculate that load diff --git a/test/Transforms/DeadStoreElimination/volatile-load.ll b/test/Transforms/DeadStoreElimination/volatile-load.ll new file mode 100644 index 00000000000..c458284dca7 --- /dev/null +++ b/test/Transforms/DeadStoreElimination/volatile-load.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -dse | llvm-dis | grep {volatile load} + +@g_1 = global i32 0 + +define void @foo() nounwind { + %t = volatile load i32* @g_1 + ret void +}