[llvm] ebec984 - [AliasAnalysis] Misc fixes for checking aliasing with scalable types.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 18 12:29:10 PDT 2020
Author: Eli Friedman
Date: 2020-03-18T12:28:47-07:00
New Revision: ebec984e14af89331ccdd9861008f4cec4589df0
URL: https://github.com/llvm/llvm-project/commit/ebec984e14af89331ccdd9861008f4cec4589df0
DIFF: https://github.com/llvm/llvm-project/commit/ebec984e14af89331ccdd9861008f4cec4589df0.diff
LOG: [AliasAnalysis] Misc fixes for checking aliasing with scalable types.
This is fixing up various places that use the implicit
TypeSize->uint64_t conversion.
The new overloads in MemoryLocation.h are already used in various places
that construct a MemoryLocation from a TypeSize, including MemorySSA.
(They were using the implicit conversion before.)
Differential Revision: https://reviews.llvm.org/D76249
Added:
llvm/test/Analysis/MemorySSA/scalable-vec.ll
Modified:
llvm/include/llvm/Analysis/MemoryLocation.h
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/IR/Value.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/MemoryLocation.h b/llvm/include/llvm/Analysis/MemoryLocation.h
index dd576e039151..446041119c80 100644
--- a/llvm/include/llvm/Analysis/MemoryLocation.h
+++ b/llvm/include/llvm/Analysis/MemoryLocation.h
@@ -89,6 +89,11 @@ class LocationSize {
: Value(Raw > MaxValue ? Unknown : Raw) {}
static LocationSize precise(uint64_t Value) { return LocationSize(Value); }
+ static LocationSize precise(TypeSize Value) {
+ if (Value.isScalable())
+ return unknown();
+ return precise(Value.getFixedSize());
+ }
static LocationSize upperBound(uint64_t Value) {
// You can't go lower than 0, so give a precise result.
@@ -98,6 +103,11 @@ class LocationSize {
return unknown();
return LocationSize(Value | ImpreciseBit, Direct);
}
+ static LocationSize upperBound(TypeSize Value) {
+ if (Value.isScalable())
+ return unknown();
+ return upperBound(Value.getFixedSize());
+ }
constexpr static LocationSize unknown() {
return LocationSize(Unknown, Direct);
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 427e6fd3ace2..be0feeb9237e 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -633,6 +633,10 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) {
if (!I.getAllocatedType()->isSized())
return unknown();
+ if (I.getAllocatedType()->isVectorTy() &&
+ I.getAllocatedType()->getVectorIsScalable())
+ return unknown();
+
APInt Size(IntTyBits, DL.getTypeAllocSize(I.getAllocatedType()));
if (!I.isArrayAllocation())
return std::make_pair(align(Size, I.getAlignment()), Zero);
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 8cd589759eab..962e67437280 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -666,7 +666,7 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
if (DerefBytes == 0 && (A->hasByValAttr() || A->hasStructRetAttr())) {
Type *PT = cast<PointerType>(A->getType())->getElementType();
if (PT->isSized())
- DerefBytes = DL.getTypeStoreSize(PT);
+ DerefBytes = DL.getTypeStoreSize(PT).getKnownMinSize();
}
if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes();
@@ -707,14 +707,15 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
}
} else if (auto *AI = dyn_cast<AllocaInst>(this)) {
if (!AI->isArrayAllocation()) {
- DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
+ DerefBytes =
+ DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize();
CanBeNull = false;
}
} else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
// TODO: Don't outright reject hasExternalWeakLinkage but set the
// CanBeNull flag.
- DerefBytes = DL.getTypeStoreSize(GV->getValueType());
+ DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize();
CanBeNull = false;
}
}
diff --git a/llvm/test/Analysis/MemorySSA/scalable-vec.ll b/llvm/test/Analysis/MemorySSA/scalable-vec.ll
new file mode 100644
index 000000000000..23072876a2d7
--- /dev/null
+++ b/llvm/test/Analysis/MemorySSA/scalable-vec.ll
@@ -0,0 +1,25 @@
+; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s
+; RUN: opt -aa-pipeline=basic-aa -passes='print<memoryssa>' -verify-memoryssa -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK-LABEL: define <vscale x 4 x i32> @f(
+; CHECK: 1 = MemoryDef(liveOnEntry)
+; CHECK: MemoryUse(1) MustAlias
+define <vscale x 4 x i32> @f(<vscale x 4 x i32> %z) {
+ %a = alloca <vscale x 4 x i32>
+ store <vscale x 4 x i32> %z, <vscale x 4 x i32>* %a
+ %zz = load <vscale x 4 x i32>, <vscale x 4 x i32>* %a
+ ret <vscale x 4 x i32> %zz
+}
+
+; CHECK-LABEL: define i32 @g(
+; CHECK: 1 = MemoryDef(liveOnEntry)
+; CHECK: MemoryUse(1) MayAlias
+declare i32* @gg(<vscale x 4 x i32>* %a)
+define i32 @g(i32 %z, i32 *%bb) {
+ %a = alloca <vscale x 4 x i32>
+ %aa = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* %a, i32 0, i32 0
+ store i32 %z, i32* %aa
+ %bbb = call i32* @gg(<vscale x 4 x i32>* %a) readnone
+ %zz = load i32, i32* %bbb
+ ret i32 %zz
+}
More information about the llvm-commits
mailing list