[llvm] [Analysis] Add Scalable field in MemoryLocation.h (PR #65759)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 8 06:59:42 PDT 2023
https://github.com/harviniriawan created https://github.com/llvm/llvm-project/pull/65759:
This is the first of a series of patch to improve Alias Analysis on
Scalable quantities.
Keep Scalable information from TypeSize which
will be used in Alias Analysis.
>From bfca2395647912647fa7164a08ded760539e0ef4 Mon Sep 17 00:00:00 2001
From: Harvin Iriawan <harvin.iriawan at arm.com>
Date: Fri, 8 Sep 2023 10:33:34 +0100
Subject: [PATCH] [Analysis] Add Scalable field in MemoryLocation.h
This is the first of a series of patch to improve Alias Analysis on
Scalable quantities.
Keep Scalable information from TypeSize which
will be used in Alias Analysis.
---
llvm/include/llvm/Analysis/MemoryLocation.h | 23 +++++++++++++++------
llvm/lib/Analysis/BasicAliasAnalysis.cpp | 4 ++++
llvm/lib/Analysis/MemoryLocation.cpp | 4 +++-
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/Analysis/MemoryLocation.h b/llvm/include/llvm/Analysis/MemoryLocation.h
index 85ca84e68a13971..6276db994ac1ea0 100644
--- a/llvm/include/llvm/Analysis/MemoryLocation.h
+++ b/llvm/include/llvm/Analysis/MemoryLocation.h
@@ -77,6 +77,7 @@ class LocationSize {
};
uint64_t Value;
+ bool Scalable = false;
// Hack to support implicit construction. This should disappear when the
// public LocationSize ctor goes away.
@@ -97,13 +98,17 @@ class LocationSize {
// Since the overwhelming majority of users of this provide precise values,
// this assumes the provided value is precise.
constexpr LocationSize(uint64_t Raw)
- : Value(Raw > MaxValue ? AfterPointer : Raw) {}
-
- static LocationSize precise(uint64_t Value) { return LocationSize(Value); }
+ : Value(Raw > MaxValue ? AfterPointer : Raw), Scalable(false) {}
+ constexpr LocationSize(uint64_t Raw, bool Scalable)
+ : Value(Raw > MaxValue ? AfterPointer : Raw), Scalable(Scalable) {}
+
+ // Make construction of LocationSize that takes in uint64_t to set Scalable
+ // information as false
+ static LocationSize precise(uint64_t Value) {
+ return LocationSize(Value, false /*Scalable*/);
+ }
static LocationSize precise(TypeSize Value) {
- if (Value.isScalable())
- return afterPointer();
- return precise(Value.getFixedValue());
+ return LocationSize(Value.getKnownMinValue(), Value.isScalable());
}
static LocationSize upperBound(uint64_t Value) {
@@ -168,6 +173,8 @@ class LocationSize {
return (Value & ImpreciseBit) == 0;
}
+ bool isScalable() const { return Scalable; }
+
// Convenience method to check if this LocationSize's value is 0.
bool isZero() const { return hasValue() && getValue() == 0; }
@@ -292,6 +299,10 @@ class MemoryLocation {
const AAMDNodes &AATags = AAMDNodes())
: Ptr(Ptr), Size(Size), AATags(AATags) {}
+ explicit MemoryLocation(const Value *Ptr, uint64_t Size,
+ const AAMDNodes &AATags = AAMDNodes())
+ : Ptr(Ptr), Size(Size, false), AATags(AATags) {}
+
MemoryLocation getWithNewPtr(const Value *NewPtr) const {
MemoryLocation Copy(*this);
Copy.Ptr = NewPtr;
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index c162b8f6edc1905..9ba1c24e2142848 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1087,6 +1087,10 @@ AliasResult BasicAAResult::aliasGEP(
return BaseAlias;
}
+ // Bail on analysing scalable LocationSize
+ if (V1Size.isScalable() || V2Size.isScalable())
+ return AliasResult::MayAlias;
+
// If there is a constant difference between the pointers, but the difference
// is less than the size of the associated memory object, then we know
// that the objects are partially overlapping. If the difference is
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp
index 0404b32be848ce6..51eb2347e4ce556 100644
--- a/llvm/lib/Analysis/MemoryLocation.cpp
+++ b/llvm/lib/Analysis/MemoryLocation.cpp
@@ -27,8 +27,10 @@ void LocationSize::print(raw_ostream &OS) const {
OS << "mapEmpty";
else if (*this == mapTombstone())
OS << "mapTombstone";
- else if (isPrecise())
+ else if (isPrecise() & !isScalable())
OS << "precise(" << getValue() << ')';
+ else if (isPrecise() & isScalable())
+ OS << "precise(vscale x " << getValue() << ')';
else
OS << "upperBound(" << getValue() << ')';
}
More information about the llvm-commits
mailing list