[PATCH] D57040: [Analysis] Fix isSafeToLoadUnconditionally handling of volatile.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 13:31:25 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL352109: [Analysis] Fix isSafeToLoadUnconditionally handling of volatile. (authored by efriedma, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57040?vs=182841&id=183388#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57040/new/

https://reviews.llvm.org/D57040

Files:
  llvm/trunk/lib/Analysis/Loads.cpp
  llvm/trunk/test/Transforms/SROA/phi-and-select.ll


Index: llvm/trunk/lib/Analysis/Loads.cpp
===================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp
+++ llvm/trunk/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
Index: llvm/trunk/test/Transforms/SROA/phi-and-select.ll
===================================================================
--- llvm/trunk/test/Transforms/SROA/phi-and-select.ll
+++ llvm/trunk/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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57040.183388.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190124/6a83dc24/attachment.bin>


More information about the llvm-commits mailing list