[Mlir-commits] [mlir] [mlir][TOSA] Fix folding of fp casts to bool (PR #232254)

Luke Hutton llvmlistbot at llvm.org
Thu Oct 15 04:52:52 PDT 2026


================
@@ -1524,6 +1524,25 @@ func.func @test_fold_i32_to_i1_cast() -> tensor<i1> {
 
 // -----
 
+// Fold both signed zeros to false and nonzero fractions to true.
+// CHECK-LABEL: @test_fold_f32_to_i1_cast
+// CHECK-DAG: %[[FALSE:.*]] = tosa.const values(dense<false> : tensor<i1>)
+// CHECK-DAG: %[[TRUE:.*]] = tosa.const values(dense<true> : tensor<i1>)
+// CHECK: return %[[FALSE]], %[[FALSE]], %[[TRUE]], %[[TRUE]]
+func.func @test_fold_f32_to_i1_cast() -> (tensor<i1>, tensor<i1>, tensor<i1>, tensor<i1>) {
+  %zero = "tosa.const"() <{values = dense<0.0> : tensor<f32>}> : () -> tensor<f32>
+  %neg_zero = "tosa.const"() <{values = dense<-0.0> : tensor<f32>}> : () -> tensor<f32>
+  %positive = "tosa.const"() <{values = dense<0.01> : tensor<f32>}> : () -> tensor<f32>
+  %negative = "tosa.const"() <{values = dense<-0.01> : tensor<f32>}> : () -> tensor<f32>
----------------
lhutton1 wrote:

nit: it would be nice to have some tests for special values such as NaN, inf as well

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


More information about the Mlir-commits mailing list