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

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 09:56:27 PDT 2024


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

>From 52415ec80bed661835597cb3429ea8a06894b5dd Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Thu, 28 Mar 2024 09:25:55 -0700
Subject: [PATCH 1/2] [GISEL] G_SPLAT_VECTOR can take a splat that is smaller
 than the vector element

This is what SelectionDAG does. We'd like to reuse SelectionDAG patterns.
---
 llvm/docs/GlobalISel/GenericOpcode.rst            | 4 ++++
 llvm/lib/CodeGen/MachineVerifier.cpp              | 7 ++++---
 llvm/test/MachineVerifier/test_g_splat_vector.mir | 4 ++--
 3 files changed, 10 insertions(+), 5 deletions(-)

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..00074349776fa7 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 %0
 ...

>From 4c615b52d0501aeb6210daa1aee1181efd27fd55 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Thu, 28 Mar 2024 09:55:49 -0700
Subject: [PATCH 2/2] fixup! add break statement

---
 llvm/lib/CodeGen/MachineVerifier.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index e568a379b213e6..7c7a40230350c1 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1768,17 +1768,23 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
     LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
     LLT SrcTy = MRI->getType(MI->getOperand(1).getReg());
 
-    if (!DstTy.isScalableVector())
+    if (!DstTy.isScalableVector()) {
       report("Destination type must be a scalable vector", MI);
+      break;
+    }
 
-    if (!SrcTy.isScalar())
+    if (!SrcTy.isScalar()) {
       report("Source type must be a scalar", MI);
+      break;
+    }
 
     if (TypeSize::isKnownGT(DstTy.getScalarType().getSizeInBits(),
-                            SrcTy.getSizeInBits()))
+                            SrcTy.getSizeInBits())) {
       report("Element type of the destination must be the same size or smaller "
              "than the source type",
              MI);
+      break;
+    }
 
     break;
   }



More information about the llvm-commits mailing list