Skip to content

[BasicAA] Treat ExtractValue(Argument) similar to Argument in relation to function-local objects. #134716

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
Apr 8, 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
14 changes: 12 additions & 2 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,16 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
return Alias;
}

// Return true for an Argument or extractvalue(Argument). These are all known
// to not alias with FunctionLocal objects and can come up from coerced function
// arguments.
static bool isArgumentOrArgumentLike(const Value *V) {
if (isa<Argument>(V))
return true;
auto *E = dyn_cast<ExtractValueInst>(V);
return E && isa<Argument>(E->getOperand(0));
}

/// Provides a bunch of ad-hoc rules to disambiguate in common cases, such as
/// array references.
AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
Expand Down Expand Up @@ -1585,8 +1595,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,

// Function arguments can't alias with things that are known to be
// unambigously identified at the function level.
if ((isa<Argument>(O1) && isIdentifiedFunctionLocal(O2)) ||
(isa<Argument>(O2) && isIdentifiedFunctionLocal(O1)))
if ((isArgumentOrArgumentLike(O1) && isIdentifiedFunctionLocal(O2)) ||
(isArgumentOrArgumentLike(O2) && isIdentifiedFunctionLocal(O1)))
return AliasResult::NoAlias;

// If one pointer is the result of a call/invoke or load and the other is a
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Analysis/BasicAA/noalias-inttoptr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define void @test_extractvalue([2 x ptr] %Q.coerce) {
; Same as test_extractvalue with an escape of %P
define void @test_extractvalue_escape([2 x ptr] %Q.coerce) {
; CHECK-LABEL: Function: test_extractvalue_escape:
; CHECK: MayAlias: i8* %P, i8* %Q
; CHECK: NoAlias: i8* %P, i8* %Q
%P = alloca i8
call void @escape(ptr %P)
%Q = extractvalue [2 x ptr] %Q.coerce, 1
Expand Down
Loading