[Mlir-commits] [mlir] Draft: [mlir][tosa] Fix unranked tosa canonicalizations crashes (PR #188188)
Hocky Yudhiono
llvmlistbot at llvm.org
Tue Mar 24 20:51:02 PDT 2026
================
@@ -1736,8 +1757,10 @@ OpFoldResult ResizeOp::fold(FoldAdaptor adaptor) {
}
auto input = getInput();
- auto inputTy = llvm::cast<RankedTensorType>(input.getType());
- auto resultTy = llvm::cast<RankedTensorType>(getType());
+ auto inputTy = llvm::dyn_cast<RankedTensorType>(input.getType());
+ auto resultTy = llvm::dyn_cast<RankedTensorType>(getType());
+ if (!inputTy || !resultTy)
----------------
hockyy wrote:
```
// CHECK-LABEL: @fold_resize_identity_scale_to_unranked
func.func @fold_resize_identity_scale_to_unranked(%arg0 : tensor<1x15x13x1xf32>) -> tensor<*xf32> {
// CHECK: tosa.resize
%scale = tosa.const_shape { values = dense<[1, 1, 1, 1]> : tensor<4xindex> } : () -> !tosa.shape<4>
%offset = tosa.const_shape { values = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2>
%border = tosa.const_shape { values = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2>
%resize = tosa.resize %arg0, %scale, %offset, %border {mode = NEAREST_NEIGHBOR} : (tensor<1x15x13x1xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<*xf32>
return %resize : tensor<*xf32>
}
// -----
// Same parameters except scale_y_n != scale_y_d: fold must not apply.
// CHECK-LABEL: @resize_nofold_asymmetric_y_scale
func.func @resize_nofold_asymmetric_y_scale(%arg0 : tensor<1x15x13x1xf32>) -> tensor<1x29x13x1xf32> {
// CHECK: tosa.resize
%scale = tosa.const_shape { values = dense<[4, 2, 1, 1]> : tensor<4xindex> } : () -> !tosa.shape<4>
%offset = tosa.const_shape { values = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2>
%border = tosa.const_shape { values = dense<0> : tensor<2xindex> } : () -> !tosa.shape<2>
%resize = tosa.resize %arg0, %scale, %offset, %border {mode = NEAREST_NEIGHBOR} : (tensor<1x15x13x1xf32>, !tosa.shape<4>, !tosa.shape<2>, !tosa.shape<2>) -> tensor<1x29x13x1xf32>
return %resize : tensor<1x29x13x1xf32>
}
```
I added this two. Your point is correct.
https://github.com/llvm/llvm-project/pull/188188
More information about the Mlir-commits
mailing list