[llvm] c23e1cb - [BasicAA] Treat ExtractValue(Argument) similar to Argument in relation to function-local objects. (#134716)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 8 02:06:02 PDT 2025
Author: David Green
Date: 2025-04-08T10:05:58+01:00
New Revision: c23e1cb9362067d3565a78590db8c5e68b74cf17
URL: https://github.com/llvm/llvm-project/commit/c23e1cb9362067d3565a78590db8c5e68b74cf17
DIFF: https://github.com/llvm/llvm-project/commit/c23e1cb9362067d3565a78590db8c5e68b74cf17.diff
LOG: [BasicAA] Treat ExtractValue(Argument) similar to Argument in relation to function-local objects. (#134716)
This is a much smaller, technically orthogonal patch similar to #134505. It
states that a extractvalue(Argument) can be treated like an Argument for alias
analysis, where the extractelement acts like a phi / copy. No inttoptr here.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/noalias-inttoptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 4d1a95a0c4b43..12d9c8706a8e1 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -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,
@@ -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
diff --git a/llvm/test/Analysis/BasicAA/noalias-inttoptr.ll b/llvm/test/Analysis/BasicAA/noalias-inttoptr.ll
index 72f9adc5a74bf..cdfdb091f668f 100644
--- a/llvm/test/Analysis/BasicAA/noalias-inttoptr.ll
+++ b/llvm/test/Analysis/BasicAA/noalias-inttoptr.ll
@@ -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
More information about the llvm-commits
mailing list