mirror-llvm-project/mlir
Andrzej Warzyński de5cef3127
[mlir][vector] Extend combineContractAndBroadcast to accept vector.shape_cast (#208752)
`combineContractAndBroadcast` is a pattern that matches
`vector.contract` operations whose inputs are defined by
`vector.broadcast`, e.g.:

```mlir
%0 = vector.broadcast %lhs : vector<8x4xi32> to vector<1x8x4xi32>
%1 = vector.broadcast %rhs : vector<8x4xi32> to vector<1x8x4xi32>
%result = vector.contract {
    indexing_maps = [#map0, #map1, #map2],
    iterator_types = ["reduction", "parallel", "parallel", "reduction"],
    kind = #vector.kind<add>
  } %0, %1, %acc : vector<1x8x4xi32>, vector<1x8x4xi32> into vector<8x8xi32>
```

The pattern folds away the reduction over a unit dimension introduced by
the defining operations, producing a simplified `vector.contract`:

```mlir
vector.contract {
  indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP2]]]
  iterator_types = ["parallel", "parallel", "reduction"]
} %0, %1, %acc : vector<8x4xi32>, vector<8x4xi32> into vector<8x8xi32>
```

This change extends the pattern to also accept broadcast-like
`vector.shape_cast` operations:

```mlir
%0 = vector.shape_cast %lhs : vector<8x4xi32> to vector<1x8x4xi32>
%1 = vector.shape_cast %rhs : vector<8x4xi32> to vector<1x8x4xi32>
%result = vector.contract {
    indexing_maps = [#map0, #map1, #map2],
    iterator_types = ["reduction", "parallel", "parallel", "reduction"],
    kind = #vector.kind<add>
  } %0, %1, %acc : vector<1x8x4xi32>, vector<1x8x4xi32> into vector<8x8xi32>
```

Note that `mlir::vector::isBroadcastableTo` was only moved to make it
available to the newly introduced `ShapeCastOp` helper,
`ShapeCastOp::isBroadcastLike()`.
2026-07-17 15:45:40 +00:00
..
benchmark/python
cmake/modules [MLIR] Normalize path separator in MLIRConfig.cmake (#208659) 2026-07-13 12:52:37 +00:00
docs [NFC][mlir][nvvm] move OptimizeForNVVM to its own directory (#206520) 2026-06-29 22:17:29 +00:00
examples [mlir][python] Set a static version in the standalone example pyproject.toml (#207860) 2026-07-06 16:26:54 -07:00
include [mlir][vector] Extend combineContractAndBroadcast to accept vector.shape_cast (#208752) 2026-07-17 15:45:40 +00:00
lib [mlir][vector] Extend combineContractAndBroadcast to accept vector.shape_cast (#208752) 2026-07-17 15:45:40 +00:00
python [MLIR][Python] Add ConditionallySpeculatable interface and Pure specifier (#195505) 2026-05-05 11:22:33 +08:00
test [mlir][vector] Extend combineContractAndBroadcast to accept vector.shape_cast (#208752) 2026-07-17 15:45:40 +00:00
tools [MLIR] Install missing standalone helper tools (#205066) 2026-07-13 09:33:38 +01:00
unittests [mlir][acc] Fix leaks in cg unit tests (#209339) 2026-07-14 00:02:05 +00:00
utils [NFC] [MLIR] fix typo in argument desc (#209587) 2026-07-14 18:40:46 +00:00
.clang-format
.clang-tidy [MLIR][NFC] Ignore clang-tidy modernize-use-using check in C code (#180326) 2026-02-09 13:24:08 +08:00
CMakeLists.txt [CMake] Warn when the version of CMake is older than 3.31.0 (#204203) 2026-06-29 11:16:27 -07:00
LICENSE.TXT
Maintainers.md [mlir][x86] Move AMX dialect into X86 dialect (#183717) 2026-03-02 11:47:30 +01:00
README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.