[PATCH] D116118: [funcattrs] Use callsite param attributes from indirect calls when inferring access attributes

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 22 18:23:14 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee5d5e19f99d: [funcattrs] Use callsite param attributes from indirect calls when inferring… (authored by reames).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116118

Files:
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Transforms/FunctionAttrs/readattrs.ll


Index: llvm/test/Transforms/FunctionAttrs/readattrs.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/readattrs.ll
+++ llvm/test/Transforms/FunctionAttrs/readattrs.ll
@@ -146,3 +146,42 @@
   store i8 0, i8* %addr.ld
   ret void
 }
+
+
+; CHECK: define void @fptr_test1a(i8* nocapture readnone %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test1a(i8* %p, void (i8*)* %f) {
+  call void %f(i8* nocapture readnone %p)
+  ret void
+}
+
+; CHECK: define void @fptr_test1b(i8* %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test1b(i8* %p, void (i8*)* %f) {
+  ; Can't infer readnone here because call might capture %p
+  call void %f(i8* readnone %p)
+  ret void
+}
+
+; CHECK: define void @fptr_test1c(i8* readnone %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test1c(i8* %p, void (i8*)* %f) {
+  call void %f(i8* readnone %p) readonly
+  ret void
+}
+
+; CHECK: define void @fptr_test2a(i8* nocapture readonly %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test2a(i8* %p, void (i8*)* %f) {
+  call void %f(i8* nocapture readonly %p)
+  ret void
+}
+
+; CHECK: define void @fptr_test2b(i8* %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test2b(i8* %p, void (i8*)* %f) {
+  ; Can't infer readonly here because call might capture %p
+  call void %f(i8* readonly %p)
+  ret void
+}
+
+; CHECK: define void @fptr_test2c(i8* readonly %p, void (i8*)* nocapture readonly %f)
+define void @fptr_test2c(i8* %p, void (i8*)* %f) {
+  call void %f(i8* readonly %p) readonly
+  ret void
+}
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -710,22 +710,13 @@
       if (CB.doesNotAccessMemory())
         continue;
 
-      Function *F = CB.getCalledFunction();
-      if (!F) {
-        if (CB.onlyReadsMemory()) {
-          IsRead = true;
-          continue;
-        }
-        return Attribute::None;
-      }
-
-      if (CB.isArgOperand(U) && UseIndex < F->arg_size() &&
-          SCCNodes.count(F->getArg(UseIndex))) {
-        // This is an argument which is part of the speculative SCC.  Note that
-        // only operands corresponding to formal arguments of the callee can
-        // participate in the speculation.
-        break;
-      }
+      if (Function *F = CB.getCalledFunction())
+        if (CB.isArgOperand(U) && UseIndex < F->arg_size() &&
+            SCCNodes.count(F->getArg(UseIndex)))
+          // This is an argument which is part of the speculative SCC.  Note
+          // that only operands corresponding to formal arguments of the callee
+          // can participate in the speculation.
+          break;
 
       // The accessors used on call site here do the right thing for calls and
       // invokes with operand bundles.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116118.395956.patch
Type: text/x-patch
Size: 2929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211223/f4f0dc96/attachment.bin>


More information about the llvm-commits mailing list