[PATCH] D57040: [Analysis] Fix isSafeToLoadUnconditionally handling of volatile.
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 21 17:34:27 PST 2019
efriedma created this revision.
efriedma added a reviewer: hfinkel.
A volatile operation cannot be used to prove an address points to normal memory. (LangRef was recently updated to state this explicitly.)
This issue was found by inspection; I think it's unlikely to show up in real code.
Repository:
rL LLVM
https://reviews.llvm.org/D57040
Files:
lib/Analysis/Loads.cpp
test/Transforms/SROA/phi-and-select.ll
Index: test/Transforms/SROA/phi-and-select.ll
===================================================================
--- test/Transforms/SROA/phi-and-select.ll
+++ test/Transforms/SROA/phi-and-select.ll
@@ -632,3 +632,15 @@
%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
+}
Index: lib/Analysis/Loads.cpp
===================================================================
--- lib/Analysis/Loads.cpp
+++ lib/Analysis/Loads.cpp
@@ -280,9 +280,17 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57040.182841.patch
Type: text/x-patch
Size: 1507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/d8e1051d/attachment.bin>
More information about the llvm-commits
mailing list