[Mlir-commits] [mlir] [mlir][tosa] Harden folds/canonicalizations for unranked and dynamic shapes (PR #188188)
Hocky Yudhiono
llvmlistbot at llvm.org
Thu Mar 26 19:14:40 PDT 2026
================
@@ -28,6 +28,41 @@ func.func @try_fold_equal_with_unranked_tensor(%arg0: tensor<4xi32>, %arg1: tens
// -----
+// CHECK-LABEL: func @try_fold_unranked_constant_results
+func.func @try_fold_unranked_constant_results() {
+ // CHECK: tosa.equal
+ // CHECK: tosa.greater
+ // CHECK: tosa.greater_equal
+ // CHECK: tosa.cast
+ // CHECK: tosa.reciprocal
+ // CHECK-NEXT: return
+ %lhs = arith.constant dense<1> : tensor<1xi32>
+ %rhs = arith.constant dense<2> : tensor<1xi32>
+ %f = arith.constant dense<2.0> : tensor<1xf32>
+ %0 = tosa.equal %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
+ %1 = tosa.greater %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
+ %2 = tosa.greater_equal %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
+ %3 = tosa.cast %lhs : (tensor<1xi32>) -> tensor<*xf32>
+ %4 = tosa.reciprocal %f : (tensor<1xf32>) -> tensor<*xf32>
----------------
hockyy wrote:
<img width="756" height="315" alt="image" src="https://github.com/user-attachments/assets/23ae2744-cab0-46d7-bb9c-1f2a996151fa" />
<img width="776" height="350" alt="image" src="https://github.com/user-attachments/assets/33f00cf1-aee0-4f3b-912c-c3654a8447c6" />
It seems like the current flow only has one call site for the `UnaryFolder`, which is from `unaryShapeFold`. Of which another 3 call sites are from some ops which output is tosa shape.
wdyt
<img width="892" height="72" alt="image" src="https://github.com/user-attachments/assets/aee1eb55-16bc-448f-9581-af6c9906a123" />
https://github.com/llvm/llvm-project/pull/188188
More information about the Mlir-commits
mailing list