<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87050>87050</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR][Arith] Convert `arith.truncf` with rounding mode to SPIR-V
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
mlir:spirv,
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
victor-eds
</td>
</tr>
</table>
<pre>
#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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVU2P4jgQ_TXmUuoosUkChxyaZiKNtDOD2NEc9tJynArxTrAjuwLL_vqVQ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