Skip to content

Commit 904d0c2

Browse files
authored
[Inline] Only consider provenance captures for scoped alias metadata (#138540)
When determining whether an escape source may alias with a noalias argument, only take provenance captures into account. If only the address of the argument was captured, an access through the escape source is not legal.
1 parent 29db305 commit 904d0c2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,9 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
13131313
// nocapture only guarantees that no copies outlive the function, not
13141314
// that the value cannot be locally captured.
13151315
if (!RequiresNoCaptureBefore ||
1316-
!PointerMayBeCapturedBefore(A, /* ReturnCaptures */ false, I, &DT))
1316+
!capturesAnything(PointerMayBeCapturedBefore(
1317+
A, /*ReturnCaptures=*/false, I, &DT, /*IncludeI=*/false,
1318+
CaptureComponents::Provenance)))
13171319
NoAliases.push_back(NewScopes[A]);
13181320
}
13191321

llvm/test/Transforms/Inline/noalias-escape-source.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ define void @test_addr_only_capture(ptr %p) {
8282
; CHECK-SAME: ptr [[P:%.*]]) {
8383
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META6:![0-9]+]])
8484
; CHECK-NEXT: call void @capture(ptr captures(address) [[P]])
85-
; CHECK-NEXT: [[P2_I:%.*]] = call ptr @get_ptr()
85+
; CHECK-NEXT: [[P2_I:%.*]] = call ptr @get_ptr(), !noalias [[META6]]
8686
; CHECK-NEXT: [[V_I:%.*]] = load i32, ptr [[P]], align 4, !alias.scope [[META6]]
87-
; CHECK-NEXT: store i32 [[V_I]], ptr [[P2_I]], align 4
87+
; CHECK-NEXT: store i32 [[V_I]], ptr [[P2_I]], align 4, !noalias [[META6]]
8888
; CHECK-NEXT: ret void
8989
;
9090
call void @callee_addr_only_capture(ptr %p)

0 commit comments

Comments
 (0)