From 333de690ea730abd3b23945c0605ebda290ce1b7 Mon Sep 17 00:00:00 2001 From: Cullen Rhodes Date: Mon, 30 Nov 2020 11:35:46 +0000 Subject: [PATCH] [IR] Disallow scalable vectors in ShuffleVectorInst::isExtractSubvectorMask It's not possible to express an extract subvector shuffle mask for a scalable vector. Reviewed By: david-arm Differential Revision: https://reviews.llvm.org/D92312 --- llvm/include/llvm/IR/Instructions.h | 9 +++++++++ llvm/unittests/IR/InstructionsTest.cpp | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index eb85597..4b08de6 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -2268,6 +2268,10 @@ public: static bool isExtractSubvectorMask(const Constant *Mask, int NumSrcElts, int &Index) { assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant."); + // Not possible to express a shuffle mask for a scalable vector for this + // case. + if (isa(Mask->getType())) + return false; SmallVector MaskAsInts; getShuffleMask(Mask, MaskAsInts); return isExtractSubvectorMask(MaskAsInts, NumSrcElts, Index); @@ -2275,6 +2279,11 @@ public: /// Return true if this shuffle mask is an extract subvector mask. bool isExtractSubvectorMask(int &Index) const { + // Not possible to express a shuffle mask for a scalable vector for this + // case. + if (isa(getType())) + return false; + int NumSrcElts = cast(Op<0>()->getType())->getNumElements(); return isExtractSubvectorMask(ShuffleMask, NumSrcElts, Index); diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index b2cfa89..f98ef4b 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -1073,6 +1073,17 @@ TEST(InstructionsTest, ShuffleMaskQueries) { EXPECT_FALSE(Id12->isIdentityWithExtract()); EXPECT_FALSE(Id12->isConcat()); delete Id12; + + // Not possible to express shuffle mask for scalable vector for extract + // subvector. + Type *VScaleV4Int32Ty = ScalableVectorType::get(Int32Ty, 4); + ShuffleVectorInst *Id13 = + new ShuffleVectorInst(Constant::getAllOnesValue(VScaleV4Int32Ty), + UndefValue::get(VScaleV4Int32Ty), + Constant::getNullValue(VScaleV4Int32Ty)); + int Index = 0; + EXPECT_FALSE(Id13->isExtractSubvectorMask(Index)); + delete Id13; } TEST(InstructionsTest, GetSplat) { -- 2.7.4