[Mlir-commits] [mlir] 2dbb7d6 - [mlir][SPIR-V] Lower arith.convertf operation (#212817)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Sep 22 06:47:34 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-09-22T15:47:27+02:00
New Revision: 2dbb7d6c55600791b7a26d0bf1ebc8daa278247d
URL: https://github.com/llvm/llvm-project/commit/2dbb7d6c55600791b7a26d0bf1ebc8daa278247d
DIFF: https://github.com/llvm/llvm-project/commit/2dbb7d6c55600791b7a26d0bf1ebc8daa278247d.diff
LOG: [mlir][SPIR-V] Lower arith.convertf operation (#212817)
Lower arith.convertf (same-bitwidth casts like f16<->bf16) to
spirv.FConvert
Added:
Modified:
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
mlir/test/Conversion/ArithToSPIRV/arith-to-spirv.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 6478c188d7d2a..40c0ac7064fdb 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -1502,6 +1502,7 @@ void mlir::arith::populateArithToSPIRVPatterns(
TypeCastingOpPattern<arith::ExtFOp, spirv::FConvertOp>,
TruncIPattern, TruncII1Pattern,
TypeCastingOpPattern<arith::TruncFOp, spirv::FConvertOp>,
+ TypeCastingOpPattern<arith::ConvertFOp, spirv::FConvertOp>,
IntToFPPattern<arith::UIToFPOp, spirv::ConvertUToFOp, false>,
BoolToValuePattern<arith::UIToFPOp>,
IntToFPPattern<arith::SIToFPOp, spirv::ConvertSToFOp, true>,
diff --git a/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv.mlir b/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv.mlir
index 4cef06992727b..123dc08031311 100644
--- a/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv.mlir
+++ b/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv.mlir
@@ -1158,6 +1158,43 @@ func.func @fptosi2(%arg0 : f16) -> i16 {
// -----
+module attributes {
+ spirv.target_env = #spirv.target_env<
+ #spirv.vce<v1.0, [Float16, BFloat16TypeKHR], [SPV_KHR_bfloat16]>, #spirv.resource_limits<>>
+} {
+
+// CHECK-LABEL: @convertf_f16_to_bf16
+func.func @convertf_f16_to_bf16(%arg0 : f16) -> bf16 {
+ // CHECK: spirv.FConvert %{{.*}} : f16 to bf16
+ %0 = arith.convertf %arg0 : f16 to bf16
+ return %0 : bf16
+}
+
+// CHECK-LABEL: @convertf_bf16_to_f16
+func.func @convertf_bf16_to_f16(%arg0 : bf16) -> f16 {
+ // CHECK: spirv.FConvert %{{.*}} : bf16 to f16
+ %0 = arith.convertf %arg0 : bf16 to f16
+ return %0 : f16
+}
+
+// CHECK-LABEL: @convertf_vector_f16_to_bf16
+func.func @convertf_vector_f16_to_bf16(%arg0 : vector<4xf16>) -> vector<4xbf16> {
+ // CHECK: spirv.FConvert %{{.*}} : vector<4xf16> to vector<4xbf16>
+ %0 = arith.convertf %arg0 : vector<4xf16> to vector<4xbf16>
+ return %0 : vector<4xbf16>
+}
+
+// CHECK-LABEL: @convertf_rounding_mode
+func.func @convertf_rounding_mode(%arg0 : f16) -> bf16 {
+ // CHECK: spirv.FConvert %{{.*}} {fp_rounding_mode = #spirv.fp_rounding_mode<RTE>} : f16 to bf16
+ %0 = arith.convertf %arg0 to_nearest_even : f16 to bf16
+ return %0 : bf16
+}
+
+} // end module
+
+// -----
+
// Checks that cast types will be adjusted when missing special capabilities for
// certain non-32-bit scalar types.
module attributes {
More information about the Mlir-commits
mailing list