[PATCH] D124655: [IR][CostModel] A scalable vector shuffle can't be an identity shuffle.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 21:55:17 PDT 2022


craig.topper created this revision.
craig.topper added reviewers: lebedev.ri, rogfer01, frasercrmck, sdesmalen.
Herald added subscribers: StephenFan, dexonsmith, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: alextsao1999, pcwang-thead, MaskRay.
Herald added a project: LLVM.

Even if the minimum number of elements is 1 and the length doesn't change,
we don't know what vscale is so its not guaranteed to be an identity
shuffle. Since the only possible shuffle mask value is 0 or undef, it's
really a broadcast or undefined.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124655

Files:
  llvm/include/llvm/IR/Instructions.h
  llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll


Index: llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
===================================================================
--- llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
+++ llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
@@ -11,7 +11,7 @@
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %3 = shufflevector <vscale x 8 x i16> undef, <vscale x 8 x i16> undef, <vscale x 8 x i32> zeroinitializer
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %4 = shufflevector <vscale x 2 x i32> undef, <vscale x 2 x i32> undef, <vscale x 2 x i32> zeroinitializer
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %5 = shufflevector <vscale x 4 x i32> undef, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
-; CHECK-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %6 = shufflevector <vscale x 1 x i64> undef, <vscale x 1 x i64> undef, <vscale x 1 x i32> zeroinitializer
+; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %6 = shufflevector <vscale x 1 x i64> undef, <vscale x 1 x i64> undef, <vscale x 1 x i32> zeroinitializer
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %7 = shufflevector <vscale x 2 x i64> undef, <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %8 = shufflevector <vscale x 16 x i1> undef, <vscale x 16 x i1> undef, <vscale x 16 x i32> zeroinitializer
 ; CHECK-NEXT:  Cost Model: Invalid cost for instruction: %9 = shufflevector <vscale x 8 x i1> undef, <vscale x 8 x i1> undef, <vscale x 8 x i32> zeroinitializer
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -2137,6 +2137,12 @@
   static bool isIdentityMask(ArrayRef<int> Mask);
   static bool isIdentityMask(const Constant *Mask) {
     assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant.");
+
+    // Not possible to express a shuffle mask for a scalable vector for this
+    // case.
+    if (isa<ScalableVectorType>(Mask->getType()))
+      return false;
+
     SmallVector<int, 16> MaskAsInts;
     getShuffleMask(Mask, MaskAsInts);
     return isIdentityMask(MaskAsInts);
@@ -2147,6 +2153,11 @@
   /// from its input vectors.
   /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef>
   bool isIdentity() const {
+    // Not possible to express a shuffle mask for a scalable vector for this
+    // case.
+    if (isa<ScalableVectorType>(getType()))
+      return false;
+
     return !changesLength() && isIdentityMask(ShuffleMask);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124655.425968.patch
Type: text/x-patch
Size: 2643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220429/788ff3d4/attachment.bin>


More information about the llvm-commits mailing list