[llvm] 0616e99 - [InstSimplify][SVE] Fix SimplifyGEPInst for scalable vector.
Huihui Zhang via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 16 11:46:27 PDT 2020
Author: Huihui Zhang
Date: 2020-03-16T11:46:12-07:00
New Revision: 0616e9964b9ef2e2cb12790515610e7cdd0042e3
URL: https://github.com/llvm/llvm-project/commit/0616e9964b9ef2e2cb12790515610e7cdd0042e3
DIFF: https://github.com/llvm/llvm-project/commit/0616e9964b9ef2e2cb12790515610e7cdd0042e3.diff
LOG: [InstSimplify][SVE] Fix SimplifyGEPInst for scalable vector.
Summary:
Skip folds that rely on DataLayout::getTypeAllocSize(). For scalable
vector, only minimal type alloc size is known at compile-time.
Reviewers: sdesmalen, efriedma, spatel, apazos
Reviewed By: efriedma
Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D75892
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/vscale.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index bc9ae5ebffb0..6ea140f31ef4 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4081,13 +4081,16 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
if (isa<UndefValue>(Ops[0]))
return UndefValue::get(GEPTy);
+ bool IsScalableVec =
+ SrcTy->isVectorTy() ? SrcTy->getVectorIsScalable() : false;
+
if (Ops.size() == 2) {
// getelementptr P, 0 -> P.
if (match(Ops[1], m_Zero()) && Ops[0]->getType() == GEPTy)
return Ops[0];
Type *Ty = SrcTy;
- if (Ty->isSized()) {
+ if (!IsScalableVec && Ty->isSized()) {
Value *P;
uint64_t C;
uint64_t TyAllocSize = Q.DL.getTypeAllocSize(Ty);
@@ -4135,7 +4138,7 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
}
}
- if (Q.DL.getTypeAllocSize(LastType) == 1 &&
+ if (!IsScalableVec && Q.DL.getTypeAllocSize(LastType) == 1 &&
all_of(Ops.slice(1).drop_back(1),
[](Value *Idx) { return match(Idx, m_Zero()); })) {
unsigned IdxWidth =
diff --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll
index 5a6971c9e292..d112128042c2 100644
--- a/llvm/test/Transforms/InstSimplify/vscale.ll
+++ b/llvm/test/Transforms/InstSimplify/vscale.ll
@@ -94,3 +94,42 @@ define i32 @insert_extract_element_same_vec_idx_2(<vscale x 4 x i32> %a) {
ret i32 %r
}
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Memory Access and Addressing Operations
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; getelementptr
+
+define <vscale x 4 x i32*> @getelementptr_constant_foldable_1() {
+; CHECK-LABEL: @getelementptr_constant_foldable_1(
+; CHECK-NEXT: ret <vscale x 4 x i32*> zeroinitializer
+;
+ %ptr = getelementptr i32, <vscale x 4 x i32*> zeroinitializer, <vscale x 4 x i64> undef
+ ret <vscale x 4 x i32*> %ptr
+}
+
+define <vscale x 4 x <vscale x 4 x i32>*> @getelementptr_constant_foldable_2() {
+; CHECK-LABEL: @getelementptr_constant_foldable_2(
+; CHECK-NEXT: ret <vscale x 4 x <vscale x 4 x i32>*> zeroinitializer
+;
+ %ptr = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, <vscale x 4 x i64> undef
+ ret <vscale x 4 x <vscale x 4 x i32>*> %ptr
+}
+
+; fold getelementptr P, 0 -> P.
+define <vscale x 4 x i32>* @getelementptr_constant_foldable_3() {
+; CHECK-LABEL: @getelementptr_constant_foldable_3(
+; CHECK-NEXT: ret <vscale x 4 x i32>* null
+;
+ %ptr = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, i64 0
+ ret <vscale x 4 x i32>* %ptr
+}
+
+define <vscale x 4 x i32>* @getelementptr_not_constant_foldable(i64 %x) {
+; CHECK-LABEL: @getelementptr_not_constant_foldable(
+; CHECK-NEXT: [[PTR:%.*]] = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, i64 [[X:%.*]]
+; CHECK-NEXT: ret <vscale x 4 x i32>* [[PTR]]
+;
+ %ptr = getelementptr <vscale x 4 x i32>, <vscale x 4 x i32>* null, i64 %x
+ ret <vscale x 4 x i32>* %ptr
+}
More information about the llvm-commits
mailing list