[Mlir-commits] [mlir] Draft: [mlir][tosa] Fix unranked tosa canonicalizations crashes (PR #188188)

Hocky Yudhiono llvmlistbot at llvm.org
Tue Mar 24 19:52:11 PDT 2026


================
@@ -906,6 +906,26 @@ func.func @fold_resize_bilinear(%arg0 : tensor<1x15x13x1xi8>) -> tensor<1x15x13x
 
 // -----
 
+// CHECK-LABEL: @dont_canonicalize_unranked_clamp
+func.func @dont_canonicalize_unranked_clamp(%arg0 : tensor<*xf32>) -> tensor<*xf32> {
+  // CHECK: tosa.clamp
+  %0 = tosa.clamp %arg0 {min_val = 0.0 : f32, max_val = 1.0 : f32} : (tensor<*xf32>) -> tensor<*xf32>
+  return %0 : tensor<*xf32>
+}
+
+// -----
+
+// CHECK-LABEL: @dont_canonicalize_unranked_slice_dynamic_size
+func.func @dont_canonicalize_unranked_slice_dynamic_size(%arg0: tensor<1x4xf32>) -> tensor<*xf32> {
+  // CHECK: tosa.slice
+  %start = tosa.const_shape {values = dense<[0, 0]> : tensor<2xindex>} : () -> !tosa.shape<2>
+  %size = tosa.const_shape {values = dense<[1, -1]> : tensor<2xindex>} : () -> !tosa.shape<2>
+  %0 = tosa.slice %arg0, %start, %size : (tensor<1x4xf32>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<*xf32>
----------------
hockyy wrote:

```
hocky at hocky:~/llvm-project$ mlir-opt checker.mlir --tosa-infer-shapes
module {
  func.func @dont_canonicalize_unranked_slice_dynamic_size(%arg0: tensor<1x4xf32>) -> tensor<*xf32> {
    %0 = tosa.const_shape  {values = dense<0> : tensor<2xindex>} : () -> !tosa.shape<2>
    %1 = tosa.const_shape  {values = dense<[1, -1]> : tensor<2xindex>} : () -> !tosa.shape<2>
    %2 = tosa.slice %arg0, %0, %1 : (tensor<1x4xf32>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<1x4xf32>
    %cast = tensor.cast %2 : tensor<1x4xf32> to tensor<*xf32>
    return %cast : tensor<*xf32>
  }
}

hocky at hocky:~/llvm-project$ 

```

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


More information about the Mlir-commits mailing list