[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
Tue Dec 21 10:05:28 PST 2021


reames created this revision.
reames added reviewers: nikic, jdoerfert, sstefan1, aeubanks.
Herald added subscribers: ormris, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

Arguments to an indirect call is by definition outside the SCC, but there's no reason we can't use locally defined facts on the call site.  This also has the nice effect of further simplifying the code.


Repository:
  rG LLVM Github Monorepo

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.395712.patch
Type: text/x-patch
Size: 2929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211221/c602dc85/attachment.bin>


More information about the llvm-commits mailing list