[PATCH] D156841: [CaptureTracking] Allow non-void `noalias` return funcs to be non-capturing

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 18:44:35 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, fhahn, efriedma, nlopes.
Herald added subscribers: jeroen.dobbelaere, StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This only applies for readonly/nounwind functions from which capturing
can only happen via the return value. If the return is `noalias`, its
guranteed to not be based on any incoming pointer argument so is safe
to be assumed not to be capturing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156841

Files:
  llvm/lib/Analysis/CaptureTracking.cpp
  llvm/test/Transforms/FunctionAttrs/nocapture.ll


Index: llvm/test/Transforms/FunctionAttrs/nocapture.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/nocapture.ll
+++ llvm/test/Transforms/FunctionAttrs/nocapture.ll
@@ -558,7 +558,7 @@
 
 define ptr @noalias_ret(ptr %f, ptr %p) {
 ; CHECK-LABEL: define ptr @noalias_ret
-; CHECK-SAME: (ptr nocapture readonly [[F:%.*]], ptr readonly [[P:%.*]]) #[[ATTR5]] {
+; CHECK-SAME: (ptr nocapture readonly [[F:%.*]], ptr nocapture readonly [[P:%.*]]) #[[ATTR5]] {
 ; CHECK-NEXT:    [[R:%.*]] = call noalias ptr [[F]](ptr [[P]]) #[[ATTR8]]
 ; CHECK-NEXT:    ret ptr [[R]]
 ;
Index: llvm/lib/Analysis/CaptureTracking.cpp
===================================================================
--- llvm/lib/Analysis/CaptureTracking.cpp
+++ llvm/lib/Analysis/CaptureTracking.cpp
@@ -314,8 +314,8 @@
     // its return value and doesn't unwind (a readonly function can leak bits
     // by throwing an exception or not depending on the input value).
     if (Call->onlyReadsMemory() && Call->doesNotThrow() &&
-        Call->getType()->isVoidTy())
-      return UseCaptureKind::NO_CAPTURE;
+        (Call->getType()->isVoidTy() || Call->returnDoesNotAlias()))
+        return UseCaptureKind::NO_CAPTURE;
 
     // The pointer is not captured if returned pointer is not captured.
     // NOTE: CaptureTracking users should not assume that only functions


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156841.546287.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230802/912dc2af/attachment.bin>


More information about the llvm-commits mailing list