[MLIR] can the tensor.reshape transform into tensor.collapse_shape and tensor.expand_shape?

I want to transform the code snip with tensor.reshape into tensor.collapse_shape and tensor.expand_shape

%reshape = tensor.reshape %expanded(%inserted_23) : (tensor<1x?xi64>, tensor<2xindex>) → tensor<?x?xi64>

I try to use the following code snip to equivalent expression it, and the deepseek thinks it is ok, but the doubao thinks they are not (They are popular AI tools), so I don’t have the idea which is right ? If there is a tool similar alive2 for llvm is better.

%collapsed = tensor.collapse_shape %expanded [[0, 1]] : tensor<1x?xi64> into tensor<?xi64>

%dim0 = tensor.extract %inserted_23[0] : tensor<2xindex>

%dim1 = tensor.extract %inserted_23[1] : tensor<2xindex>

%reshaped = tensor.expand_shape %collapsed output_shape [%dim0, %dim1] reassociation = [[0, 1]] : tensor<?xi64> into tensor<?x?xi64>

ps:can also be get from godbolt

I think this transformation looks valid reassociation.It’s mathematical equivalence because this transforms perserve element count and ordering.
The proposed transformation using collapse_shape + expand_shape is indeed equivalent to the original tensor.reshape operation. DeepSeek’s analysis was correct for this specific case, while Doubao appears to have been overly conservative about potential edge cases.