[PATCH] D81620: [SVE] Make getSplatValue work for some scalable vector splats
Christopher Tetreault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 14:02:33 PDT 2020
ctetreau updated this revision to Diff 271475.
ctetreau added a comment.
fixed issues with previous implementation, used new functionality to enable scalable vector indices to GEP, and added test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81620/new/
https://reviews.llvm.org/D81620
Files:
llvm/lib/IR/Constants.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/IR/Instructions.cpp
llvm/test/Transforms/InstSimplify/gep.ll
Index: llvm/test/Transforms/InstSimplify/gep.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/gep.ll
+++ llvm/test/Transforms/InstSimplify/gep.ll
@@ -168,4 +168,12 @@
ret <vscale x 4 x i32*> %gep
}
+define <vscale x 4 x float*> @scalable_vector_idx_mix_scalar_vector() {
+; CHECK-LABEL: @scalable_vector_idx_mix_scalar_vector(
+; CHECK-NEXT: ret <vscale x 4 x float*> getelementptr (%struct, <vscale x 4 x %struct*> zeroinitializer, <vscale x 4 x i64> zeroinitializer, <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i32 0), <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer))
+;
+ %gep = getelementptr %struct, <vscale x 4 x %struct*> zeroinitializer, i32 0, <vscale x 4 x i32> shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i32 0), <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer)
+ ret <vscale x 4 x float*> %gep
+}
+
; Check ConstantExpr::getGetElementPtr() using ElementCount for size queries - end.
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -3222,8 +3222,7 @@
// FIXME: Check address space sizes here
if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
- if (cast<FixedVectorType>(SrcVecTy)->getNumElements() ==
- cast<FixedVectorType>(DestVecTy)->getNumElements()) {
+ if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
// An element by element cast. Find the appropriate opcode based on the
// element types.
SrcTy = SrcVecTy->getElementType();
Index: llvm/lib/IR/DataLayout.cpp
===================================================================
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -815,8 +815,7 @@
unsigned NumBits = getIndexTypeSizeInBits(Ty);
IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
- return FixedVectorType::get(IntTy,
- cast<FixedVectorType>(VecTy)->getNumElements());
+ return VectorType::get(IntTy, VecTy);
return IntTy;
}
Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -1521,6 +1521,27 @@
return CV->getSplatValue();
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
return CV->getSplatValue(AllowUndefs);
+
+ // Check if this is a constant expression splat of the form returned by
+ // ConstantVector::getSplat()
+ auto *Shuf = dyn_cast<ConstantExpr>(this);
+ if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
+ isa<UndefValue>(Shuf->getOperand(1))) {
+
+ auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
+ if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
+ isa<UndefValue>(IElt->getOperand(0))) {
+
+ ArrayRef<int> Mask = Shuf->getShuffleMask();
+ Constant *SplatVal = IElt->getOperand(1);
+ ConstantInt *Index = cast<ConstantInt>(IElt->getOperand(2));
+
+ if (Index->getValue() == 0 &&
+ std::all_of(Mask.begin(), Mask.end(), [](int I) { return I == 0; }))
+ return SplatVal;
+ }
+ }
+
return nullptr;
}
@@ -1554,9 +1575,8 @@
const APInt &Constant::getUniqueInteger() const {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
return CI->getValue();
- assert(this->getSplatValue() && "Doesn't contain a unique integer!");
- const Constant *C = this->getAggregateElement(0U);
- assert(C && isa<ConstantInt>(C) && "Not a vector of numbers!");
+ Constant *C = this->getSplatValue();
+ assert(C && isa<ConstantInt>(C) && "Doesn't contain a unique integer!");
return cast<ConstantInt>(C)->getValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81620.271475.patch
Type: text/x-patch
Size: 3999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200617/c333a7a5/attachment.bin>
More information about the llvm-commits
mailing list