[mlir][linalg] Fix bug in InferStaticShapeOfOperands pattern
authorVladislav Vinogradov <v.vinogradov@yadro.com>
Thu, 10 Nov 2022 10:23:44 +0000 (13:23 +0300)
committerVladislav Vinogradov <v.vinogradov@yadro.com>
Wed, 16 Nov 2022 09:19:16 +0000 (12:19 +0300)
commit2ada5cbea47bdf7d8df70981315f352237cc2222
treedbfb9f5043dec095c569b158e1ac7ed76f75bece
parent981dac8bd6fef375847e81ea5df19d4e760532b8
[mlir][linalg] Fix bug in InferStaticShapeOfOperands pattern

The pattern tries to deduce static shape from `tensor.cast` producer of linalg operation operands.
The original code unconditionally casts type of the `tensor.cast` source to `RankedTensorType`.
But the `tensor.cast` can also operate on `UnrankedTensorType`, so this cast either fail on assertion
in debug build or introduce UB in release build.

The patch replaces unconditional cast with `dyn_cast` and check for the cast result.

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D137775
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/test/Dialect/Linalg/canonicalize.mlir