[all-commits] [llvm/llvm-project] dbb782: [mlir][shape] Turn `ShapeOfOp` folding into canoni...
Matthias Springer via All-commits
all-commits at lists.llvm.org
Tue Dec 5 16:41:37 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: dbb782dffdbd37e4aafa745eba9ba0f2831e21e8
https://github.com/llvm/llvm-project/commit/dbb782dffdbd37e4aafa745eba9ba0f2831e21e8
Author: Matthias Springer <me at m-sp.org>
Date: 2023-12-06 (Wed, 06 Dec 2023)
Changed paths:
M mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
M mlir/lib/Dialect/Shape/IR/Shape.cpp
M mlir/test/Dialect/Shape/canonicalize.mlir
Log Message:
-----------
[mlir][shape] Turn `ShapeOfOp` folding into canonicalization pattern (#74438)
The `ShapeOfOp` folder used to generate invalid IR.
Input:
```
%0 = shape.shape_of %arg1 : tensor<index> -> tensor<?xindex>
```
Output:
```
%0 = "shape.const_shape"() <{shape = dense<> : tensor<0xindex>}> : () -> tensor<?xindex>
error: 'shape.const_shape' op inferred type(s) 'tensor<0xindex>' are incompatible with return type(s) of operation 'tensor<?xindex>'
```
This rewrite cannot be implemented as a folder because the result type
may have to change. In the above example, the original `shape.shape_of`
op had a return type of `tensor<?xindex>`, but the folded attribute
(materialized as a `shape.const_shape` op) must have a type of
`tensor<0xf32>` to be valid.
This commit fixes tests such as
`mlir/test/Dialect/Shape/canonicalize.mlir` when verifying the IR after
each pattern application (#74270).
More information about the All-commits
mailing list