Skip to content

Commit 3a9fe78

Browse files
committed
fixup! [Analysis] Add Scalable field in MemoryLocation.h
1 parent eaed8a7 commit 3a9fe78

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

llvm/include/llvm/Analysis/MemoryLocation.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Value;
6464
//
6565
// If asked to represent a pathologically large value, this will degrade to
6666
// std::nullopt.
67+
// Store Scalable information in bit 62 of Value. Scalable information is
68+
// required to do Alias Analysis on Scalable quantities
6769
class LocationSize {
6870
enum : uint64_t {
6971
BeforeOrAfterPointer = ~uint64_t(0),
@@ -164,10 +166,12 @@ class LocationSize {
164166
bool hasValue() const {
165167
return Value != AfterPointer && Value != BeforeOrAfterPointer;
166168
}
167-
uint64_t getValue() const {
169+
bool isScalable() const { return (Value & ScalableBit); }
170+
171+
TypeSize getValue() const {
168172
assert(hasValue() && "Getting value from an unknown LocationSize!");
169173
assert((Value & ~(ImpreciseBit | ScalableBit)) < MaxValue && "Scalable bit of value should be masked");
170-
return Value & ~(ImpreciseBit | ScalableBit);
174+
return {Value & ~(ImpreciseBit | ScalableBit), isScalable()};
171175
}
172176

173177
// Returns whether or not this value is precise. Note that if a value is
@@ -176,10 +180,11 @@ class LocationSize {
176180
return (Value & ImpreciseBit) == 0;
177181
}
178182

179-
bool isScalable() const { return (Value & ScalableBit); }
180183

181184
// Convenience method to check if this LocationSize's value is 0.
182-
bool isZero() const { return hasValue() && getValue() == 0; }
185+
bool isZero() const {
186+
return hasValue() && getValue().getKnownMinValue() == 0;
187+
}
183188

184189
/// Whether accesses before the base pointer are possible.
185190
bool mayBeBeforePointer() const { return Value == BeforeOrAfterPointer; }

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ static LocationSize getMinimalExtentFrom(const Value &V,
179179
// If queried with a precise location size, we assume that location size to be
180180
// accessed, thus valid.
181181
if (LocSize.isPrecise())
182-
DerefBytes = std::max(DerefBytes, LocSize.getValue());
182+
DerefBytes = std::max(DerefBytes, LocSize.getValue().getKnownMinValue());
183183
return LocationSize(DerefBytes, LocSize.isScalable());
184184
}
185185

186186
/// Returns true if we can prove that the object specified by V has size Size.
187-
static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
187+
static bool isObjectSize(const Value *V, TypeSize Size, const DataLayout &DL,
188188
const TargetLibraryInfo &TLI, bool NullIsValidLoc) {
189189
LocationSize ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc);
190190
return ObjectSize != MemoryLocation::UnknownSize && ObjectSize.getValue() == Size;

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ static bool HasAddressTaken(const Instruction *AI, TypeSize AllocSize,
176176
const auto *I = cast<Instruction>(U);
177177
// If this instruction accesses memory make sure it doesn't access beyond
178178
// the bounds of the allocated object.
179+
// TODO: TypeSize::getFixed should be modified to adapt to scalable vectors
179180
std::optional<MemoryLocation> MemLoc = MemoryLocation::getOrNone(I);
180-
if (MemLoc && MemLoc->Size.hasValue() &&
181+
if (MemLoc && MemLoc->Size.hasValue() && !MemLoc->Size.isScalable() &&
181182
!TypeSize::isKnownGE(AllocSize,
182183
TypeSize::getFixed(MemLoc->Size.getValue())))
183184
return true;

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ static bool isShortenableAtTheBeginning(Instruction *I) {
205205
return isa<AnyMemSetInst>(I);
206206
}
207207

208-
static uint64_t getPointerSize(const Value *V, const DataLayout &DL,
209-
const TargetLibraryInfo &TLI,
210-
const Function *F) {
208+
static LocationSize getPointerSize(const Value *V, const DataLayout &DL,
209+
const TargetLibraryInfo &TLI,
210+
const Function *F) {
211211
uint64_t Size;
212212
ObjectSizeOpts Opts;
213213
Opts.NullIsUnknownSize = NullPointerIsDefined(F);
214214

215215
if (getObjectSize(V, Size, DL, &TLI, Opts))
216-
return Size;
217-
return MemoryLocation::UnknownSize;
216+
return LocationSize(Size, DL.getTypeAllocSize(V->getType()).isScalable());
217+
return LocationSize(MemoryLocation::UnknownSize);
218218
}
219219

220220
namespace {
@@ -959,9 +959,10 @@ struct DSEState {
959959
// Check whether the killing store overwrites the whole object, in which
960960
// case the size/offset of the dead store does not matter.
961961
if (DeadUndObj == KillingUndObj && KillingLocSize.isPrecise()) {
962-
uint64_t KillingUndObjSize = getPointerSize(KillingUndObj, DL, TLI, &F);
963-
if (KillingUndObjSize != MemoryLocation::UnknownSize &&
964-
KillingUndObjSize == KillingLocSize.getValue())
962+
LocationSize KillingUndObjSize =
963+
getPointerSize(KillingUndObj, DL, TLI, &F);
964+
if (KillingUndObjSize.hasValue() &&
965+
KillingUndObjSize.getValue() == KillingLocSize.getValue())
965966
return OW_Complete;
966967
}
967968

@@ -984,9 +985,15 @@ struct DSEState {
984985
return isMaskedStoreOverwrite(KillingI, DeadI, BatchAA);
985986
}
986987

987-
const uint64_t KillingSize = KillingLocSize.getValue();
988-
const uint64_t DeadSize = DeadLoc.Size.getValue();
988+
const TypeSize KillingSize = KillingLocSize.getValue();
989+
const TypeSize DeadSize = DeadLoc.Size.getValue();
990+
const bool AnyScalable =
991+
DeadSize.isScalable() || KillingLocSize.isScalable();
989992

993+
// TODO: Remove AnyScalable constraint once alias analysis fully support
994+
// scalable quantities
995+
if (AnyScalable)
996+
return OW_Unknown;
990997
// Query the alias information
991998
AliasResult AAR = BatchAA.alias(KillingLoc, DeadLoc);
992999

0 commit comments

Comments
 (0)