[llvm] r352109 - [Analysis] Fix isSafeToLoadUnconditionally handling of volatile.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 24 13:31:14 PST 2019
Author: efriedma
Date: Thu Jan 24 13:31:13 2019
New Revision: 352109
URL: http://llvm.org/viewvc/llvm-project?rev=352109&view=rev
Log:
[Analysis] Fix isSafeToLoadUnconditionally handling of volatile.
A volatile operation cannot be used to prove an address points to normal
memory. (LangRef was recently updated to state it explicitly.)
Differential Revision: https://reviews.llvm.org/D57040
Modified:
llvm/trunk/lib/Analysis/Loads.cpp
llvm/trunk/test/Transforms/SROA/phi-and-select.ll
Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=352109&r1=352108&r2=352109&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Thu Jan 24 13:31:13 2019
@@ -280,9 +280,17 @@ bool llvm::isSafeToLoadUnconditionally(V
Value *AccessedPtr;
unsigned AccessedAlign;
if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
+ // Ignore volatile loads. The execution of a volatile load cannot
+ // be used to prove an address is backed by regular memory; it can,
+ // for example, point to an MMIO register.
+ if (LI->isVolatile())
+ continue;
AccessedPtr = LI->getPointerOperand();
AccessedAlign = LI->getAlignment();
} else if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
+ // Ignore volatile stores (see comment for loads).
+ if (SI->isVolatile())
+ continue;
AccessedPtr = SI->getPointerOperand();
AccessedAlign = SI->getAlignment();
} else
Modified: llvm/trunk/test/Transforms/SROA/phi-and-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SROA/phi-and-select.ll?rev=352109&r1=352108&r2=352109&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SROA/phi-and-select.ll (original)
+++ llvm/trunk/test/Transforms/SROA/phi-and-select.ll Thu Jan 24 13:31:13 2019
@@ -632,3 +632,15 @@ exit:
%result = load i32, i32* %phi, align 4
ret i32 %result
}
+
+; Don't speculate a load based on an earlier volatile operation.
+define i8 @volatile_select(i8* %p, i1 %b) {
+; CHECK-LABEL: @volatile_select(
+; CHECK: select i1 %b, i8* %p, i8* %p2
+ %p2 = alloca i8
+ store i8 0, i8* %p2
+ store volatile i8 0, i8* %p
+ %px = select i1 %b, i8* %p, i8* %p2
+ %v2 = load i8, i8* %px
+ ret i8 %v2
+}
More information about the llvm-commits
mailing list