[llvm-branch-commits] [llvm] 66c2aaa - FunctionAttrs: Check all uses when inferring captures for argument SCCs (#231536)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Nov 15 12:05:42 PST 2026
Author: Matt Arsenault
Date: 2026-11-15T21:04:39+01:00
New Revision: 66c2aaaaf0487f0b8acd5a590988b43d73d1404f
URL: https://github.com/llvm/llvm-project/commit/66c2aaaaf0487f0b8acd5a590988b43d73d1404f
DIFF: https://github.com/llvm/llvm-project/commit/66c2aaaaf0487f0b8acd5a590988b43d73d1404f.diff
LOG: FunctionAttrs: Check all uses when inferring captures for argument SCCs (#231536)
When merging the capture components of an SCC of arguments, only the
first use of each argument was considered, because of a misplaced break.
If an argument was passed to another argument in the SCC first and to a
capturing argument outside of it later, it was incorrectly inferred to
not be captured.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
(cherry picked from commit 05b3eeffba9f93d14a9f79af253c4769d8c01827)
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/FunctionAttrs/arg_returned.ll
llvm/test/Transforms/FunctionAttrs/nocapture.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index d98d3a1c46309d..cce9b6b1da341a 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1367,7 +1367,6 @@ static void addArgumentAttrs(const SCCNodeSet &SCCNodes,
CC |= Use->CC;
else
CC |= CaptureComponents(A->getAttributes().getCaptureInfo());
- break;
}
if (capturesAll(CC))
break;
diff --git a/llvm/test/Transforms/FunctionAttrs/arg_returned.ll b/llvm/test/Transforms/FunctionAttrs/arg_returned.ll
index 21e76620f0a990..7096feb15d5255 100644
--- a/llvm/test/Transforms/FunctionAttrs/arg_returned.ll
+++ b/llvm/test/Transforms/FunctionAttrs/arg_returned.ll
@@ -260,8 +260,8 @@ entry:
; TEST another SCC test
;
-; FNATTR: define ptr @rt2_helper(ptr nofree readnone captures(address_is_null) %a)
-; FNATTR: define ptr @rt2(ptr nofree readnone captures(address_is_null) %a, ptr nofree readnone captures(ret: address, provenance) %b)
+; FNATTR: define ptr @rt2_helper(ptr nofree readnone %a)
+; FNATTR: define ptr @rt2(ptr nofree readnone %a, ptr nofree readnone captures(ret: address, provenance) %b)
define ptr @rt2_helper(ptr %a) #0 {
entry:
%call = call ptr @rt2(ptr %a, ptr %a)
diff --git a/llvm/test/Transforms/FunctionAttrs/nocapture.ll b/llvm/test/Transforms/FunctionAttrs/nocapture.ll
index 4ff806ca6aeb6a..dc8001eceb79d9 100644
--- a/llvm/test/Transforms/FunctionAttrs/nocapture.ll
+++ b/llvm/test/Transforms/FunctionAttrs/nocapture.ll
@@ -1468,3 +1468,51 @@ define void @captures_metadata_provenance(ptr %x, ptr %y) {
declare ptr @llvm.launder.invariant.group.p0(ptr)
declare ptr @llvm.strip.invariant.group.p0(ptr)
+
+; %p is captured through @scc_capture_b, which is not the first use of %p in
+; the argument SCC.
+declare void @capture_unknown(ptr)
+
+define void @scc_capture_a(ptr %p, i1 %c) {
+; COMMON-LABEL: define void @scc_capture_a
+; COMMON-SAME: (ptr [[P:%.*]], i1 [[C:%.*]]) {
+; COMMON-NEXT: br i1 [[C]], label [[T:%.*]], label [[E:%.*]]
+; COMMON: t:
+; COMMON-NEXT: call void @scc_capture_c(ptr [[P]], i1 [[C]])
+; COMMON-NEXT: ret void
+; COMMON: e:
+; COMMON-NEXT: call void @scc_capture_b(ptr [[P]])
+; COMMON-NEXT: ret void
+;
+ br i1 %c, label %t, label %e
+
+t:
+ call void @scc_capture_c(ptr %p, i1 %c)
+ ret void
+
+e:
+ call void @scc_capture_b(ptr %p)
+ ret void
+}
+
+define void @scc_capture_b(ptr %p) {
+; COMMON-LABEL: define void @scc_capture_b
+; COMMON-SAME: (ptr [[P:%.*]]) {
+; COMMON-NEXT: call void @scc_capture_c(ptr null, i1 false)
+; COMMON-NEXT: call void @capture_unknown(ptr [[P]])
+; COMMON-NEXT: ret void
+;
+ call void @scc_capture_c(ptr null, i1 false)
+ call void @capture_unknown(ptr %p)
+ ret void
+}
+
+define void @scc_capture_c(ptr %p, i1 %c) {
+; COMMON-LABEL: define void @scc_capture_c
+; COMMON-SAME: (ptr [[P:%.*]], i1 [[C:%.*]]) {
+; COMMON-NEXT: call void @scc_capture_a(ptr [[P]], i1 [[C]])
+; COMMON-NEXT: ret void
+;
+ call void @scc_capture_a(ptr %p, i1 %c)
+ ret void
+}
More information about the llvm-branch-commits
mailing list