[llvm] f4878cb - [DAG] Add ShuffleVectorSDNode::getSplatMaskIndex static helper (#129731)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 00:05:38 PST 2025


Author: Simon Pilgrim
Date: 2025-03-05T08:05:34Z
New Revision: f4878cb916127498e04819e810b4aefca65e7348

URL: https://github.com/llvm/llvm-project/commit/f4878cb916127498e04819e810b4aefca65e7348
DIFF: https://github.com/llvm/llvm-project/commit/f4878cb916127498e04819e810b4aefca65e7348.diff

LOG: [DAG] Add ShuffleVectorSDNode::getSplatMaskIndex static helper (#129731)

Move ShuffleVectorSDNode::getSplatIndex implementation into getSplatMaskIndex static helper, and covert getSplatIndex into a wrapper similar to isSplat

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 20283ad8f2689..1c1c94e7193ae 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1663,10 +1663,13 @@ class ShuffleVectorSDNode : public SDNode {
 
   bool isSplat() const { return isSplatMask(getMask()); }
 
-  int getSplatIndex() const {
-    assert(isSplat() && "Cannot get splat index for non-splat!");
-    EVT VT = getValueType(0);
-    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
+  int getSplatIndex() const { return getSplatMaskIndex(getMask()); }
+
+  static bool isSplatMask(ArrayRef<int> Mask);
+
+  static int getSplatMaskIndex(ArrayRef<int> Mask) {
+    assert(isSplatMask(Mask) && "Cannot get splat index for non-splat!");
+    for (unsigned i = 0, e = Mask.size(); i != e; ++i)
       if (Mask[i] >= 0)
         return Mask[i];
 
@@ -1675,8 +1678,6 @@ class ShuffleVectorSDNode : public SDNode {
     return 0;
   }
 
-  static bool isSplatMask(ArrayRef<int> Mask);
-
   /// Change values in a shuffle permute mask assuming
   /// the two vector operands have swapped position.
   static void commuteMask(MutableArrayRef<int> Mask) {


        


More information about the llvm-commits mailing list