Skip to content

Conversation

@RKSimon
Copy link
Collaborator

@RKSimon RKSimon commented Mar 4, 2025

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

Move ShuffleVectorSDNode::getSplatIndex implementation into getSplatMaskIndex static helper, and covert getSplatIndex into a wrapper similar to isSplat
@RKSimon RKSimon requested review from arsenm and topperc March 4, 2025 16:07
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Simon Pilgrim (RKSimon)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/129731.diff

1 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+7-6)
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) {

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RKSimon RKSimon merged commit f4878cb into llvm:main Mar 5, 2025
10 of 13 checks passed
@RKSimon RKSimon deleted the dag-shuffle-getsplatmaskindex branch March 5, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants