Skip to content

Commit 525ef01

Browse files
author
Eli Friedman
committedJan 24, 2019
[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 llvm-svn: 352109
1 parent b0eabef commit 525ef01

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
 

Diff for: ‎llvm/lib/Analysis/Loads.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,17 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, unsigned Align,
280280
Value *AccessedPtr;
281281
unsigned AccessedAlign;
282282
if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
283+
// Ignore volatile loads. The execution of a volatile load cannot
284+
// be used to prove an address is backed by regular memory; it can,
285+
// for example, point to an MMIO register.
286+
if (LI->isVolatile())
287+
continue;
283288
AccessedPtr = LI->getPointerOperand();
284289
AccessedAlign = LI->getAlignment();
285290
} else if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {
291+
// Ignore volatile stores (see comment for loads).
292+
if (SI->isVolatile())
293+
continue;
286294
AccessedPtr = SI->getPointerOperand();
287295
AccessedAlign = SI->getAlignment();
288296
} else

Diff for: ‎llvm/test/Transforms/SROA/phi-and-select.ll

+12
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,15 @@ exit:
632632
%result = load i32, i32* %phi, align 4
633633
ret i32 %result
634634
}
635+
636+
; Don't speculate a load based on an earlier volatile operation.
637+
define i8 @volatile_select(i8* %p, i1 %b) {
638+
; CHECK-LABEL: @volatile_select(
639+
; CHECK: select i1 %b, i8* %p, i8* %p2
640+
%p2 = alloca i8
641+
store i8 0, i8* %p2
642+
store volatile i8 0, i8* %p
643+
%px = select i1 %b, i8* %p, i8* %p2
644+
%v2 = load i8, i8* %px
645+
ret i8 %v2
646+
}

0 commit comments

Comments
 (0)
Please sign in to comment.