Skip to content

Commit 20cf6b2

Browse files
committed
[BasicAA] Treat ExtractValue(Argument) similar to Argument in relation to function-local objects.
This is a much smaller, technically orthoganal patch similar to llvm#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 inttotr here. I'm hoping for this operations this is perfectly sensible, but it is quite a complex area.
1 parent 5bf7305 commit 20cf6b2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: llvm/lib/Analysis/BasicAliasAnalysis.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,16 @@ AliasResult BasicAAResult::aliasPHI(const PHINode *PN, LocationSize PNSize,
15331533
return Alias;
15341534
}
15351535

1536+
// Return true for an Argument or extractvalue(Argument). These are all known
1537+
// to not alias with FunctionLocal objects and can come up from coerced function
1538+
// arguments.
1539+
static bool isArgumentOrArgumentLike(const Value *V) {
1540+
if (isa<Argument>(V))
1541+
return true;
1542+
auto *E = dyn_cast<ExtractValueInst>(V);
1543+
return E && isa<Argument>(E->getOperand(0));
1544+
}
1545+
15361546
/// Provides a bunch of ad-hoc rules to disambiguate in common cases, such as
15371547
/// array references.
15381548
AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
@@ -1585,8 +1595,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
15851595

15861596
// Function arguments can't alias with things that are known to be
15871597
// unambigously identified at the function level.
1588-
if ((isa<Argument>(O1) && isIdentifiedFunctionLocal(O2)) ||
1589-
(isa<Argument>(O2) && isIdentifiedFunctionLocal(O1)))
1598+
if ((isArgumentOrArgumentLike(O1) && isIdentifiedFunctionLocal(O2)) ||
1599+
(isArgumentOrArgumentLike(O2) && isIdentifiedFunctionLocal(O1)))
15901600
return AliasResult::NoAlias;
15911601

15921602
// If one pointer is the result of a call/invoke or load and the other is a

Diff for: llvm/test/Analysis/BasicAA/noalias-inttoptr.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ define void @test_extractvalue([2 x ptr] %Q.coerce) {
7373
; Same as test_extractvalue with an escape of %P
7474
define void @test_extractvalue_escape([2 x ptr] %Q.coerce) {
7575
; CHECK-LABEL: Function: test_extractvalue_escape:
76-
; CHECK: MayAlias: i8* %P, i8* %Q
76+
; CHECK: NoAlias: i8* %P, i8* %Q
7777
%P = alloca i8
7878
call void @escape(ptr %P)
7979
%Q = extractvalue [2 x ptr] %Q.coerce, 1

0 commit comments

Comments
 (0)