[PATCH] D99138: [deref] Use readonly to infer global dereferenceability in a callee

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 29 17:44:08 PDT 2021


reames updated this revision to Diff 334024.
reames added a comment.

Clarify comments to avoid (subtly misleading) reasoning about inferring nosync.  While it happens to be true that atomic reads prevent readonly being inferred today, I'd rather not bake that assumption into the comment and we don't need the stronger inference anyway.


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

https://reviews.llvm.org/D99138

Files:
  llvm/lib/IR/Value.cpp
  llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll


Index: llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -260,9 +260,7 @@
 }
 
 ; CHECK-LABEL: 'infer_func_attrs2'
-; GLOBAL: %p
-; POINT-NOT: %p
-; FIXME: Can be inferred from attributes
+; CHECK: %p
 define void @infer_func_attrs2(i32* dereferenceable(8) %p) readonly {
   call void @mayfree()
   %v = load i32, i32* %p
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -760,6 +760,17 @@
   if (F->doesNotFreeMemory() && F->hasNoSync())
     return false;
 
+  // Free is modeled as writing to the freed memory, so a readonly implies
+  // nofree.  Additionally, coordination with another thread to have it free
+  // on our behalf requires at least one write to shared memory, so readonly
+  // also implies that no other thread can free it (in a well defined manner).
+  // Subtly, this is weaker than implying nosync as the later would require
+  // us to prove this thread didn't read from shared memory either.
+  // (NOTE: This case is important in practice as we don't infer nosync, but
+  // do infer readonly.)
+  if (F->onlyReadsMemory())
+    return false;
+
   // With garbage collection, deallocation typically occurs solely at or after
   // safepoints.  If we're compiling for a collector which uses the
   // gc.statepoint infrastructure, safepoints aren't explicitly present


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99138.334024.patch
Type: text/x-patch
Size: 1602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210330/988232e4/attachment.bin>


More information about the llvm-commits mailing list