[PATCH] D16857: More detailed memory dependence checking between volatile and non-volatile accesses

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 08:34:39 PST 2016


kparzysz created this revision.
kparzysz added a reviewer: dberlin.
kparzysz added a subscriber: llvm-commits.
kparzysz set the repository for this revision to rL LLVM.

Don't automatically assume depedency if only one of the memory accesses in question is volatile.  Defer the final determination of dependency to the alias analysis.
The (very simple) motivating example is added as a lit test.

Repository:
  rL LLVM

http://reviews.llvm.org/D16857

Files:
  lib/Analysis/MemoryDependenceAnalysis.cpp
  test/Transforms/GVN/volatile-nonvolatile.ll

Index: test/Transforms/GVN/volatile-nonvolatile.ll
===================================================================
--- /dev/null
+++ test/Transforms/GVN/volatile-nonvolatile.ll
@@ -0,0 +1,27 @@
+; RUN: opt -tbaa -gvn -S < %s | FileCheck %s
+; Check that we can eliminate the second load.
+; CHECK: load
+; CHECK-NOT: load
+
+%struct.t = type { i32* }
+
+define void @foo(%struct.t* nocapture readonly %p, i32 %v) #0 {
+entry:
+  %m = getelementptr inbounds %struct.t, %struct.t* %p, i32 0, i32 0
+  %0 = load i32*, i32** %m, align 4, !tbaa !1
+  store volatile i32 %v, i32* %0, align 4, !tbaa !6
+  %1 = load i32*, i32** %m, align 4, !tbaa !1
+  store volatile i32 %v, i32* %1, align 4, !tbaa !6
+  ret void
+}
+
+attributes #0 = { norecurse nounwind }
+
+!1 = !{!2, !3, i64 0}
+!2 = !{!"", !3, i64 0}
+!3 = !{!"any pointer", !4, i64 0}
+!4 = !{!"omnipotent char", !5, i64 0}
+!5 = !{!"Simple C/C++ TBAA"}
+!6 = !{!7, !7, i64 0}
+!7 = !{!"int", !4, i64 0}
+
Index: lib/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- lib/Analysis/MemoryDependenceAnalysis.cpp
+++ lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -625,7 +625,7 @@
       // Atomic stores have complications involved.
       // A Monotonic store is OK if the query inst is itself not atomic.
       // FIXME: This is overly conservative.
-      if (!SI->isUnordered()) {
+      if (!SI->isUnordered() && SI->isAtomic()) {
         if (!QueryInst)
           return MemDepResult::getClobber(SI);
         if (SI->getOrdering() != Monotonic)
@@ -645,8 +645,15 @@
       // While volatile access cannot be eliminated, they do not have to clobber
       // non-aliasing locations, as normal accesses can for example be reordered
       // with volatile accesses.
-      if (SI->isVolatile())
-        return MemDepResult::getClobber(SI);
+      if (QueryInst && SI->isVolatile()) {
+        if (LoadInst *QLI = dyn_cast<LoadInst>(QueryInst)) {
+          if (!QLI->isSimple())
+            return MemDepResult::getClobber(SI);
+        } else if (StoreInst *QSI = dyn_cast<StoreInst>(QueryInst)) {
+          if (!QSI->isSimple())
+            return MemDepResult::getClobber(SI);
+        }
+      }
 
       // If alias analysis can tell that this store is guaranteed to not modify
       // the query pointer, ignore it.  Use getModRefInfo to handle cases where


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16857.46793.patch
Type: text/x-patch
Size: 2387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160203/d6ab1d78/attachment.bin>


More information about the llvm-commits mailing list