Skip to content

[AA] Consider extractvalue and extractelement as escape sources #127640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,12 @@ bool llvm::isEscapeSource(const Value *V) {
if (isa<IntToPtrInst>(V))
return true;

// Capture tracking considers insertions into aggregates and vectors as
// captures. As such, extractions from aggregates and vectors are escape
// sources.
if (isa<ExtractValueInst, ExtractElementInst>(V))
return true;

// Same for inttoptr constant expressions.
if (auto *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::IntToPtr)
Expand Down
27 changes: 25 additions & 2 deletions llvm/test/Analysis/BasicAA/escape-source-aggregate.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

declare { ptr, i1 } @get_struct()
declare <2 x ptr> @get_vec()
declare void @escape(ptr)

; CHECK: MayAlias: i32* %a, i32* %extract
; CHECK: NoAlias: i32* %a, i32* %extract
define i32 @test_extractvalue() {
%a = alloca i32
%call = call { ptr, i1 } @get_struct()
Expand All @@ -13,7 +14,7 @@ define i32 @test_extractvalue() {
ret i32 %v
}

; CHECK: MayAlias: i32* %a, i32* %extract
; CHECK: NoAlias: i32* %a, i32* %extract
define i32 @test_extractelement() {
%a = alloca i32
%call = call <2 x ptr> @get_vec()
Expand All @@ -22,3 +23,25 @@ define i32 @test_extractelement() {
%v = load i32, ptr %a
ret i32 %v
}

; CHECK: MayAlias: i32* %a, i32* %extract
define i32 @test_extractvalue_escape() {
%a = alloca i32
call void @escape(ptr %a)
%call = call { ptr, i1 } @get_struct()
%extract = extractvalue { ptr, i1 } %call, 0
store i32 0, ptr %extract
%v = load i32, ptr %a
ret i32 %v
}

; CHECK: MayAlias: i32* %a, i32* %extract
define i32 @test_extractelement_escape() {
%a = alloca i32
call void @escape(ptr %a)
%call = call <2 x ptr> @get_vec()
%extract = extractelement <2 x ptr> %call, i32 0
store i32 0, ptr %extract
%v = load i32, ptr %a
ret i32 %v
}