[llvm] [BasicAA] Compute minimal access extents lazily (PR #226931)
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 02:42:46 PDT 2026
https://github.com/davidbolvansky updated https://github.com/llvm/llvm-project/pull/226931
>From 890d25ef723216e1f7280f2754b34cf537ec919b Mon Sep 17 00:00:00 2001
From: David Bolvansky <david.bolvansky at gmail.com>
Date: Mon, 28 Sep 2026 10:15:24 +0200
Subject: [PATCH] BasicAA: Compute minimal access extents lazily
---
llvm/lib/Analysis/BasicAliasAnalysis.cpp | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index fd9a7bb935170..52a46a3fe5a4b 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -120,8 +120,12 @@ static std::optional<TypeSize> getObjectSize(const Value *V,
/// Returns true if we can prove that the object specified by V is smaller than
/// Size. Bails out early unless the root object is passed as the first
/// parameter.
-static bool isObjectSmallerThan(const Value *V, TypeSize Size,
- const DataLayout &DL,
+static TypeSize getMinimalExtentFrom(const Value &V,
+ const LocationSize &LocSize,
+ const DataLayout &DL, bool NullIsValidLoc);
+
+static bool isObjectSmallerThan(const Value *V, const Value &OtherV,
+ LocationSize OtherSize, const DataLayout &DL,
const TargetLibraryInfo &TLI,
bool NullIsValidLoc) {
// Note that the meanings of the "object" are slightly different in the
@@ -147,6 +151,8 @@ static bool isObjectSmallerThan(const Value *V, TypeSize Size,
if (!isIdentifiedObject(V))
return false;
+ TypeSize Size = getMinimalExtentFrom(OtherV, OtherSize, DL, NullIsValidLoc);
+
// This function needs to use the aligned object size because we allow
// reads a bit past the end given sufficient alignment.
std::optional<TypeSize> ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc,
@@ -1615,12 +1621,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
// If the size of one access is larger than the entire object on the other
// side, then we know such behavior is undefined and can assume no alias.
bool NullIsValidLocation = NullPointerIsDefined(&F);
- if ((isObjectSmallerThan(
- O2, getMinimalExtentFrom(*V1, V1Size, DL, NullIsValidLocation), DL,
- TLI, NullIsValidLocation)) ||
- (isObjectSmallerThan(
- O1, getMinimalExtentFrom(*V2, V2Size, DL, NullIsValidLocation), DL,
- TLI, NullIsValidLocation)))
+ if (isObjectSmallerThan(O2, *V1, V1Size, DL, TLI, NullIsValidLocation) ||
+ isObjectSmallerThan(O1, *V2, V2Size, DL, TLI, NullIsValidLocation))
return AliasResult::NoAlias;
if (EnableSeparateStorageAnalysis) {
More information about the llvm-commits
mailing list