Skip to content

Commit aec3929

Browse files
authored
[FunctionAttrs] Only consider provenance capture in access attr inference (#138535)
For the purpose of inferring readonly/writeonly/readnone on arguments, we only care about provenance captures, not address captures.
1 parent 73a7a3d commit aec3929

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ determinePointerAccessAttrs(Argument *A,
908908
for (Use &UU : CB.uses())
909909
if (Visited.insert(&UU).second)
910910
Worklist.push_back(&UU);
911-
} else if (!CB.doesNotCapture(UseIndex)) {
911+
} else if (capturesAnyProvenance(CB.getCaptureInfo(UseIndex))) {
912912
if (!CB.onlyReadsMemory())
913913
// If the callee can save a copy into other memory, then simply
914914
// scanning uses of the call is insufficient. We have no way
@@ -1382,10 +1382,9 @@ static void addArgumentAttrs(const SCCNodeSet &SCCNodes,
13821382
}
13831383
}
13841384

1385-
// TODO(captures): Ignore address-only captures.
1386-
if (capturesAnything(CC)) {
1387-
// As the pointer may be captured, determine the pointer attributes
1388-
// looking at each argument individually.
1385+
if (capturesAnyProvenance(CC)) {
1386+
// As the pointer provenance may be captured, determine the pointer
1387+
// attributes looking at each argument individually.
13891388
for (ArgumentGraphNode *N : ArgumentSCC) {
13901389
if (DetermineAccessAttrsForSingleton(N->Definition))
13911390
Changed.insert(N->Definition->getParent());

llvm/test/Transforms/FunctionAttrs/nocapture.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ define void @dont_increase_existing_captures_scc2(ptr %p) {
12341234
define void @addr_only_scc(ptr %p) {
12351235
; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none)
12361236
; FNATTRS-LABEL: define void @addr_only_scc
1237-
; FNATTRS-SAME: (ptr captures(address_is_null) [[P:%.*]]) #[[ATTR20:[0-9]+]] {
1237+
; FNATTRS-SAME: (ptr readonly captures(address_is_null) [[P:%.*]]) #[[ATTR20:[0-9]+]] {
12381238
; FNATTRS-NEXT: [[V:%.*]] = load i8, ptr [[P]], align 1
12391239
; FNATTRS-NEXT: store i8 [[V]], ptr @g, align 1
12401240
; FNATTRS-NEXT: call void @addr_only_scc2(ptr [[P]])
@@ -1257,7 +1257,7 @@ define void @addr_only_scc(ptr %p) {
12571257
define void @addr_only_scc2(ptr %p) {
12581258
; FNATTRS: Function Attrs: nofree nosync nounwind memory(write, argmem: read, inaccessiblemem: none)
12591259
; FNATTRS-LABEL: define void @addr_only_scc2
1260-
; FNATTRS-SAME: (ptr captures(address_is_null) [[P:%.*]]) #[[ATTR20]] {
1260+
; FNATTRS-SAME: (ptr readonly captures(address_is_null) [[P:%.*]]) #[[ATTR20]] {
12611261
; FNATTRS-NEXT: [[CMP:%.*]] = icmp ne ptr [[P]], null
12621262
; FNATTRS-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]]
12631263
; FNATTRS: if:

0 commit comments

Comments
 (0)