Skip to content

Commit 104c01e

Browse files
authored
[FunctionAttrs] Only check ArgMem effects when inferring argument attrs (llvm#69571)
When inferring readonly/writeonly on arguments, if the argument is passed to a call, we should only check the ArgMem effects implied by the call -- we don't care whether the call reads/writes non-arg memory (captured pointers are not relevant here, because they will abort the analysis entirely). This also fixes a regression that was introduced when moving to MemoryEffects: The code was still checking the old WriteOnly attribute on functions, which no longer exists.
1 parent 8c88a82 commit 104c01e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ determinePointerAccessAttrs(Argument *A,
668668
Worklist.push_back(&UU);
669669
}
670670

671-
if (CB.doesNotAccessMemory())
671+
ModRefInfo ArgMR = CB.getMemoryEffects().getModRef(IRMemLocation::ArgMem);
672+
if (isNoModRef(ArgMR))
672673
continue;
673674

674675
if (Function *F = CB.getCalledFunction())
@@ -683,9 +684,9 @@ determinePointerAccessAttrs(Argument *A,
683684
// invokes with operand bundles.
684685
if (CB.doesNotAccessMemory(UseIndex)) {
685686
/* nop */
686-
} else if (CB.onlyReadsMemory() || CB.onlyReadsMemory(UseIndex)) {
687+
} else if (!isModSet(ArgMR) || CB.onlyReadsMemory(UseIndex)) {
687688
IsRead = true;
688-
} else if (CB.hasFnAttr(Attribute::WriteOnly) ||
689+
} else if (!isRefSet(ArgMR) ||
689690
CB.dataOperandHasImpliedAttr(UseIndex, Attribute::WriteOnly)) {
690691
IsWrite = true;
691692
} else {

llvm/test/Transforms/FunctionAttrs/writeonly.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ define void @direct2(ptr %p) {
215215
define void @direct2b(ptr %p) {
216216
; FNATTRS: Function Attrs: memory(write)
217217
; FNATTRS-LABEL: define {{[^@]+}}@direct2b
218-
; FNATTRS-SAME: (ptr nocapture [[P:%.*]]) #[[ATTR8]] {
218+
; FNATTRS-SAME: (ptr nocapture writeonly [[P:%.*]]) #[[ATTR8]] {
219219
; FNATTRS-NEXT: call void @direct2_callee(ptr nocapture [[P]])
220220
; FNATTRS-NEXT: ret void
221221
;
@@ -304,7 +304,7 @@ define void @fptr_test2(ptr %p, ptr %f) {
304304
define void @fptr_test3(ptr %p, ptr %f) {
305305
; FNATTRS: Function Attrs: memory(write)
306306
; FNATTRS-LABEL: define {{[^@]+}}@fptr_test3
307-
; FNATTRS-SAME: (ptr nocapture [[P:%.*]], ptr nocapture readonly [[F:%.*]]) #[[ATTR8]] {
307+
; FNATTRS-SAME: (ptr nocapture writeonly [[P:%.*]], ptr nocapture readonly [[F:%.*]]) #[[ATTR8]] {
308308
; FNATTRS-NEXT: call void [[F]](ptr nocapture [[P]]) #[[ATTR8]]
309309
; FNATTRS-NEXT: ret void
310310
;
@@ -320,7 +320,7 @@ define void @fptr_test3(ptr %p, ptr %f) {
320320

321321
define void @test_argmem_none_callee(ptr %p) {
322322
; FNATTRS-LABEL: define {{[^@]+}}@test_argmem_none_callee
323-
; FNATTRS-SAME: (ptr nocapture [[P:%.*]]) {
323+
; FNATTRS-SAME: (ptr nocapture readnone [[P:%.*]]) {
324324
; FNATTRS-NEXT: call void @direct1_callee(ptr nocapture [[P]]) #[[ATTR9:[0-9]+]]
325325
; FNATTRS-NEXT: ret void
326326
;
@@ -335,7 +335,7 @@ define void @test_argmem_none_callee(ptr %p) {
335335

336336
define void @test_argmem_read_callee(ptr %p) {
337337
; FNATTRS-LABEL: define {{[^@]+}}@test_argmem_read_callee
338-
; FNATTRS-SAME: (ptr nocapture [[P:%.*]]) {
338+
; FNATTRS-SAME: (ptr nocapture readonly [[P:%.*]]) {
339339
; FNATTRS-NEXT: call void @direct1_callee(ptr nocapture [[P]]) #[[ATTR10:[0-9]+]]
340340
; FNATTRS-NEXT: ret void
341341
;
@@ -350,7 +350,7 @@ define void @test_argmem_read_callee(ptr %p) {
350350

351351
define void @test_argmem_write_callee(ptr %p) {
352352
; FNATTRS-LABEL: define {{[^@]+}}@test_argmem_write_callee
353-
; FNATTRS-SAME: (ptr nocapture [[P:%.*]]) {
353+
; FNATTRS-SAME: (ptr nocapture writeonly [[P:%.*]]) {
354354
; FNATTRS-NEXT: call void @direct1_callee(ptr nocapture [[P]]) #[[ATTR11:[0-9]+]]
355355
; FNATTRS-NEXT: ret void
356356
;

0 commit comments

Comments
 (0)