[IR] Support scalable vectors in ShuffleVectorInst::increasesLength
authorCullen Rhodes <cullen.rhodes@arm.com>
Mon, 30 Nov 2020 11:35:46 +0000 (11:35 +0000)
committerCullen Rhodes <cullen.rhodes@arm.com>
Mon, 7 Dec 2020 10:42:48 +0000 (10:42 +0000)
Since the length of the llvm::SmallVector shufflemask is related to the
minimum number of elements in a scalable vector, it is fine to just get
the Min field of the ElementCount. This is already done for the similar
function changesLength, tests have been added for both.

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D92472

llvm/include/llvm/IR/Instructions.h
llvm/unittests/IR/InstructionsTest.cpp

index 4b08de6..00ecc2a 100644 (file)
@@ -2081,8 +2081,9 @@ public:
   /// elements than its source vectors.
   /// Example: shufflevector <2 x n> A, <2 x n> B, <1,2,3>
   bool increasesLength() const {
-    unsigned NumSourceElts =
-        cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
+    unsigned NumSourceElts = cast<VectorType>(Op<0>()->getType())
+                                 ->getElementCount()
+                                 .getKnownMinValue();
     unsigned NumMaskElts = ShuffleMask.size();
     return NumSourceElts < NumMaskElts;
   }
index f98ef4b..09260d3 100644 (file)
@@ -1083,7 +1083,19 @@ TEST(InstructionsTest, ShuffleMaskQueries) {
                             Constant::getNullValue(VScaleV4Int32Ty));
   int Index = 0;
   EXPECT_FALSE(Id13->isExtractSubvectorMask(Index));
+  EXPECT_FALSE(Id13->changesLength());
+  EXPECT_FALSE(Id13->increasesLength());
   delete Id13;
+
+  // Result has twice as many operands.
+  Type *VScaleV2Int32Ty = ScalableVectorType::get(Int32Ty, 2);
+  ShuffleVectorInst *Id14 =
+      new ShuffleVectorInst(Constant::getAllOnesValue(VScaleV2Int32Ty),
+                            UndefValue::get(VScaleV2Int32Ty),
+                            Constant::getNullValue(VScaleV4Int32Ty));
+  EXPECT_TRUE(Id14->changesLength());
+  EXPECT_TRUE(Id14->increasesLength());
+  delete Id14;
 }
 
 TEST(InstructionsTest, GetSplat) {