[Mlir-commits] [mlir] [MLIR][ARITH] Adds missing foldings for truncf (PR #128096)

Jakub Kuderski llvmlistbot at llvm.org
Fri Feb 21 13:53:44 PST 2025


================
@@ -1518,6 +1518,27 @@ LogicalResult arith::TruncIOp::verify() {
 /// can be represented without precision loss.
 OpFoldResult arith::TruncFOp::fold(FoldAdaptor adaptor) {
   auto resElemType = cast<FloatType>(getElementTypeOrSelf(getType()));
+  if (auto extOp = getOperand().getDefiningOp<arith::ExtFOp>()) {
+    Value src = extOp.getIn();
+    auto srcType = cast<FloatType>(getElementTypeOrSelf(src.getType()));
+    auto intermediateType =
+        cast<FloatType>(getElementTypeOrSelf(extOp.getType()));
+    // Check if the srcType is representable in the intermediateType
----------------
kuhar wrote:

```suggestion
    // Check if the srcType is representable in the intermediateType.
```

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


More information about the Mlir-commits mailing list