[Mlir-commits] [mlir] [mlir][spirv] Add basic support for SPV_EXT_replicated_composites (PR #147067)

Mohammadreza Ameri Mahabadian llvmlistbot at llvm.org
Mon Jul 7 01:45:46 PDT 2025


================
@@ -135,6 +135,52 @@ def SPIRV_ConstantOp : SPIRV_Op<"Constant",
   let autogenSerialization = 0;
 }
 
+
+// -----
+
+def SPIRV_EXTConstantCompositeReplicateOp : SPIRV_ExtVendorOp<"ConstantCompositeReplicate", [Pure]> {
+  let summary = [{
+    Declare a new replicated composite constant op.
+  }];
+
+  let description = [{
+    This op declares a `spiv.EXT.ConstantCompositeReplicate` which represents a
+    splat composite constant i.e. all element of composite constant have the
+    same value. This op will be serialized to SPIR-V `OpConstantCompositeReplicateEXT`.
+    The splat value must come from a non-specialization constant instruction."
+
+    #### Example:
+
+    ```mlir
+    %0 = spirv.Constant 1 : i32
+    %1 = spirv.EXT.ConstantCompositeReplicate %0 : vector<2xf32>
+
+    %2 = spirv.Constant dense<[1, 2]> : vector<2xi32>
+    %3 = spirv.EXT.ConstantCompositeReplicate %2 : !spirv.array<2 x vector<2xi32>>
+
+    %5 = spirv.EXT.ConstantCompositeReplicate %0 : vector<2xi32>
+    %6 = spirv.EXT.ConstantCompositeReplicate %5 : !spirv.array<2 x vector<2xi32>>
+    ```
+  }];
+
+  let availability = [
+    MinVersion<SPIRV_V_1_0>,
+    MaxVersion<SPIRV_V_1_6>,
+    Extension<[SPV_EXT_replicated_composites]>,
+    Capability<[SPIRV_C_ReplicatedCompositesEXT]>
+  ];
+
+  let arguments = (ins
+    SPIRV_Type:$constant
----------------
mahabadm wrote:

This is tested with `SPIRV_Composite` or `SPIRV_Scalar`, but here I wanted to be constituent with the result type of `spirv.Constant` which is `SPIRV_Type`. (I don't see any reason why the new ops may not work with the `spirv.Constant` result types which may be supported in future, e.g. structs.)
Please let me know if you think it is better to limit the result type.

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


More information about the Mlir-commits mailing list