[Mlir-commits] [mlir] [mlir][tosa] Fix integer-to-boolean cast folder (PR #150370)

Longsheng Mou llvmlistbot at llvm.org
Thu Jul 24 05:05:25 PDT 2025


================
@@ -1302,9 +1302,13 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
       auto intVal = operand.getSplatValue<APInt>();
       auto bitwidth = outETy.getIntOrFloatBitWidth();
 
+      // i1 types are boolean in TOSA
       if (trunc) {
-        intVal = intVal.trunc(bitwidth);
-        // i1 types are boolean in TOSA
+        if (outETy.isInteger(1)) {
----------------
CoTinker wrote:

If `outTy.isInteger(1)` is true, the `trunc` is always true.
Maybe like:
```
if (outTy.isInteger(1))
   ...
else if (trunc)
   ...
else if ...
```

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


More information about the Mlir-commits mailing list