Issue 87050
Summary [MLIR][Arith] Convert `arith.truncf` with rounding mode to SPIR-V
Labels enhancement, mlir:spirv, mlir
Assignees
Reporter victor-eds
    #86152 added an optional rounding mode attribute to `arith.truncf`. Due to missing infrastructure in SPIR-V, conversion to the SPIR-V dialect was not implemented as part of that PR.

SPIR-V accepts specifying an operation rounding mode using the `FPRoundingMode` decoration, receiving an [FP rounding mode](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#FP_Rounding_Mode) value. The decoration key is present in the dialect already, but we're missing a representation for the FP rounding mode values. Once we have that, we could convert:

```mlir
func.func @experimental_constrained_fptrunc(%arg0 : f64) {
  %0 = arith.truncf %arg0 tonearesteven : f64 to f32
  %1 = arith.truncf %arg0 downward : f64 to f32
  %2 = arith.truncf %arg0 upward : f64 to f32
  %3 = arith.truncf %arg0 towardzero : f64 to f32
 return
}
```

into:

```mlir
func.func @experimental_constrained_fptrunc(%arg0 : f64) {
  %0 = spirv.FConvertOp %arg0 {FPRoundingMode = #spirv.FPRoundingMode<RTE>} : f64 to f32
  %1 = spirv.FConvertOp %arg0 {FPRoundingMode = #spirv.FPRoundingMode<RTN>} : f64 to f32
  %2 = spirv.FConvertOp %arg0 {FPRoundingMode = #spirv.FPRoundingMode<RTP>} : f64 to f32
  %3 = spirv.FConvertOp %arg0 {FPRoundingMode = #spirv.FPRoundingMode<RTZ>} : f64 to f32
 return
}
```

Note there is no representation of `tonearestaway` in SPIR-V, so conversion should fail in that case.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to