[llvm] 65fc706 - [SCEV] Add support for GEPs over scalable vectors.
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 16:13:30 PDT 2020
Author: Eli Friedman
Date: 2020-03-13T16:12:45-07:00
New Revision: 65fc706ddfd758ebecc2f6c991eee3a6efde66a5
URL: https://github.com/llvm/llvm-project/commit/65fc706ddfd758ebecc2f6c991eee3a6efde66a5
DIFF: https://github.com/llvm/llvm-project/commit/65fc706ddfd758ebecc2f6c991eee3a6efde66a5.diff
LOG: [SCEV] Add support for GEPs over scalable vectors.
Because we have to use a ConstantExpr at some point, the canonical form
isn't set in stone, but this seems reasonable.
The pretty sizeof(<vscale x 4 x i32>) dumping is a relic of ancient
LLVM; I didn't have to touch that code. :)
Differential Revision: https://reviews.llvm.org/D75887
Added:
llvm/test/Analysis/ScalarEvolution/scalable-vector.ll
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 030de8cf90b7..dffbaf139c4c 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -3532,9 +3532,8 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
: SCEV::FlagAnyWrap;
const SCEV *TotalOffset = getZero(IntIdxTy);
- // The array size is unimportant. The first thing we do on CurTy is getting
- // its element type.
- Type *CurTy = ArrayType::get(GEP->getSourceElementType(), 0);
+ Type *CurTy = GEP->getType();
+ bool FirstIter = true;
for (const SCEV *IndexExpr : IndexExprs) {
// Compute the (potentially symbolic) offset in bytes for this index.
if (StructType *STy = dyn_cast<StructType>(CurTy)) {
@@ -3550,7 +3549,14 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP,
CurTy = STy->getTypeAtIndex(Index);
} else {
// Update CurTy to its element type.
- CurTy = cast<SequentialType>(CurTy)->getElementType();
+ if (FirstIter) {
+ assert(isa<PointerType>(CurTy) &&
+ "The first index of a GEP indexes a pointer");
+ CurTy = GEP->getSourceElementType();
+ FirstIter = false;
+ } else {
+ CurTy = cast<SequentialType>(CurTy)->getElementType();
+ }
// For an array, add the element offset, explicitly scaled.
const SCEV *ElementSize = getSizeOfExpr(IntIdxTy, CurTy);
// Getelementptr indices are signed.
@@ -3754,6 +3760,14 @@ const SCEV *ScalarEvolution::getSizeOfExpr(Type *IntTy, Type *AllocTy) {
// We can bypass creating a target-independent
// constant expression and then folding it back into a ConstantInt.
// This is just a compile-time optimization.
+ if (auto *VecTy = dyn_cast<VectorType>(AllocTy)) {
+ if (VecTy->isScalable()) {
+ Constant *NullPtr = Constant::getNullValue(AllocTy->getPointerTo());
+ Constant *One = ConstantInt::get(IntTy, 1);
+ Constant *GEP = ConstantExpr::getGetElementPtr(AllocTy, NullPtr, One);
+ return getSCEV(ConstantExpr::getPtrToInt(GEP, IntTy));
+ }
+ }
return getConstant(IntTy, getDataLayout().getTypeAllocSize(AllocTy));
}
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 81204fd57954..1a2253050152 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1447,7 +1447,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
break;
}
unsigned GEPOpiBits = Index->getType()->getScalarSizeInBits();
- uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
+ uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy).getKnownMinSize();
LocalKnown.Zero = LocalKnown.One = APInt(GEPOpiBits, 0);
computeKnownBits(Index, LocalKnown, Depth + 1, Q);
TrailZ = std::min(TrailZ,
diff --git a/llvm/test/Analysis/ScalarEvolution/scalable-vector.ll b/llvm/test/Analysis/ScalarEvolution/scalable-vector.ll
new file mode 100644
index 000000000000..3adb2e0b1a06
--- /dev/null
+++ b/llvm/test/Analysis/ScalarEvolution/scalable-vector.ll
@@ -0,0 +1,11 @@
+; RUN: opt -scalar-evolution -analyze < %s | FileCheck %s
+
+; CHECK: %1 = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, i32 3
+; CHECK: --> (3 * sizeof(<vscale x 4 x i32>)) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
+; CHECK: %2 = getelementptr <vscale x 1 x i64>, <vscale x 1 x i64>* %p, i32 1
+; CHECK: --> (sizeof(<vscale x 1 x i64>) + %p) U: full-set S: full-set
+define void @a(<vscale x 1 x i64> *%p) {
+ getelementptr <vscale x 4 x i32>, <vscale x 4 x i32> *null, i32 3
+ getelementptr <vscale x 1 x i64>, <vscale x 1 x i64> *%p, i32 1
+ ret void
+}
More information about the llvm-commits
mailing list