[Mlir-commits] [mlir] [MLIR][ARITH] Adds missing foldings for truncf (PR #128096)
Krzysztof Drewniak
llvmlistbot at llvm.org
Fri Feb 21 10:21:14 PST 2025
================
@@ -1517,6 +1517,22 @@ LogicalResult arith::TruncIOp::verify() {
/// Perform safe const propagation for truncf, i.e., only propagate if FP value
/// can be represented without precision loss.
OpFoldResult arith::TruncFOp::fold(FoldAdaptor adaptor) {
+ if (auto extOp = getOperand().getDefiningOp<arith::ExtFOp>()) {
----------------
krzysz00 wrote:
Ok, so, on top of let's add a test for it, I have a more fundamental issue: the set of available `extf` and `truncf` operations on various targets is not transitively closed.
That is, on some AMD cards, I can do `%y = arith.extf %x : f16 to f32` and `%z = arith.truncf %y : f32 to f8E5M2FNUZ` but absolutely can't do `arith.truncf %x : f16 to f8E5M2FNUZ`
I remember needing to go fix a similar folding (that one was for `y = trunc(ext(bf16 x to f32) to bf16)`) in LLVM because it was causing numerical correctness issues. So ... yeah, condition this on fastmath ... maybe `contract` if there's not a better flag for it
https://github.com/llvm/llvm-project/pull/128096
More information about the Mlir-commits
mailing list