[Mlir-commits] [mlir] [mlir][spirv] Add OpExtension "SPV_INTEL_tensor_float32_conversion " (PR #151337)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jul 31 11:46:02 PDT 2025


================
@@ -297,13 +300,40 @@ LogicalResult INTELConvertBF16ToFOp::verify() {
 LogicalResult INTELConvertFToBF16Op::verify() {
   auto operandType = getOperand().getType();
   auto resultType = getResult().getType();
-  // ODS checks that vector result type and vector operand type have the same
-  // shape.
-  if (auto vectorType = llvm::dyn_cast<VectorType>(operandType)) {
-    unsigned operandNumElements = vectorType.getNumElements();
-    unsigned resultNumElements =
-        llvm::cast<VectorType>(resultType).getNumElements();
-    if (operandNumElements != resultNumElements) {
+  // ODS checks that vector result type and vector operand type are
+  // non-scalable and have the same shape.
+  auto operandVectorType = dyn_cast<VectorType>(operandType);
+  auto resultVectorType = dyn_cast<VectorType>(resultType);
+  if (operandVectorType && resultVectorType) {
+    if (operandVectorType.isScalable() || resultVectorType.isScalable()) {
+      return emitOpError("scalable vectors are not supported");
+    }
+    if (operandVectorType.getNumElements() !=
+        resultVectorType.getNumElements()) {
+      return emitOpError(
+          "operand and result must have same number of elements");
+    }
+  }
+  return success();
+}
+
+//===----------------------------------------------------------------------===//
+// spirv.INTELRoundFToTF32Op
+//===----------------------------------------------------------------------===//
+
+LogicalResult INTELRoundFToTF32Op::verify() {
+  auto operandType = getOperand().getType();
+  auto resultType = getResult().getType();
+  // ODS checks that vector result type and vector operand type are
+  // non-scalable and have the same shape.
+  auto operandVectorType = dyn_cast<VectorType>(operandType);
+  auto resultVectorType = dyn_cast<VectorType>(resultType);
+  if (operandVectorType && resultVectorType) {
----------------
YixingZhang007 wrote:

Absolutely! I have removed the `verify()` function and revised the `arguments` and `results` definitions as follows.
```
  let arguments = (ins
    AnyTypeOf<[
      SPIRV_Float32,
      FixedVectorOfLengthAndType<[2, 3, 4, 8, 16], [SPIRV_Float32]>
    ]>:$operand
  );

  let results = (outs
    AnyTypeOf<[
      SPIRV_Float32,
      FixedVectorOfLengthAndType<[2, 3, 4, 8, 16], [SPIRV_Float32]>
    ]>:$result
  );
```
The same changes are also made for `SPV_INTEL_bfloat16_conversion` extension. Please feel free to let me know if any other changes needed :)

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


More information about the Mlir-commits mailing list