[llvm] [GISEL] G_SPLAT_VECTOR can take a splat that is smaller than the vector element (PR #86974)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 09:35:50 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: Michael Maitland (michaelmaitland)

<details>
<summary>Changes</summary>

This is what SelectionDAG does. We'd like to reuse SelectionDAG patterns.

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


3 Files Affected:

- (modified) llvm/docs/GlobalISel/GenericOpcode.rst (+4) 
- (modified) llvm/lib/CodeGen/MachineVerifier.cpp (+4-3) 
- (modified) llvm/test/MachineVerifier/test_g_splat_vector.mir (+2-2) 


``````````diff
diff --git a/llvm/docs/GlobalISel/GenericOpcode.rst b/llvm/docs/GlobalISel/GenericOpcode.rst
index cae2c21b80d7e7..e3ec5272c1e167 100644
--- a/llvm/docs/GlobalISel/GenericOpcode.rst
+++ b/llvm/docs/GlobalISel/GenericOpcode.rst
@@ -690,6 +690,10 @@ G_SPLAT_VECTOR
 
 Create a vector where all elements are the scalar from the source operand.
 
+The type of the operand must be equal to or smaller than the vector element
+type. If the operand is smaller than the vector element type, the scalar is
+implicitly truncated to the vector element type.
+
 Vector Reduction Operations
 ---------------------------
 
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index e4e05ce9278caf..e568a379b213e6 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1774,9 +1774,10 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
     if (!SrcTy.isScalar())
       report("Source type must be a scalar", MI);
 
-    if (DstTy.getScalarType() != SrcTy)
-      report("Element type of the destination must be the same type as the "
-             "source type",
+    if (TypeSize::isKnownGT(DstTy.getScalarType().getSizeInBits(),
+                            SrcTy.getSizeInBits()))
+      report("Element type of the destination must be the same size or smaller "
+             "than the source type",
              MI);
 
     break;
diff --git a/llvm/test/MachineVerifier/test_g_splat_vector.mir b/llvm/test/MachineVerifier/test_g_splat_vector.mir
index 0d1d8a3e6dcc64..c5d0c1b61f3915 100644
--- a/llvm/test/MachineVerifier/test_g_splat_vector.mir
+++ b/llvm/test/MachineVerifier/test_g_splat_vector.mir
@@ -22,6 +22,6 @@ body:             |
     ; CHECK: Source type must be a scalar
     %6:_(<vscale x 2 x s32>) = G_SPLAT_VECTOR %2
 
-    ; CHECK: Element type of the destination must be the same type as the source type
-    %7:_(<vscale x 2 x s64>) = G_SPLAT_VECTOR %0
+    ; CHECK: Element type of the destination must be the same size or smaller than the source type
+    %7:_(<vscale x 2 x s128>) = G_SPLAT_VECTOR %7
 ...

``````````

</details>


https://github.com/llvm/llvm-project/pull/86974


More information about the llvm-commits mailing list