[all-commits] [llvm/llvm-project] 7ce315: [mlir][vector] Improve shape_cast lowering (#140800)

James Newling via All-commits all-commits at lists.llvm.org
Thu Jun 5 10:19:00 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7ce315d14aa5c084574cc3a17552625f322e1d16
      https://github.com/llvm/llvm-project/commit/7ce315d14aa5c084574cc3a17552625f322e1d16
  Author: James Newling <james.newling at gmail.com>
  Date:   2025-06-05 (Thu, 05 Jun 2025)

  Changed paths:
    M mlir/lib/Dialect/Vector/Transforms/LowerVectorShapeCast.cpp
    M mlir/test/Dialect/Vector/vector-shape-cast-lowering-transforms.mlir

  Log Message:
  -----------
  [mlir][vector] Improve shape_cast lowering  (#140800)

Before this PR, a rank-m -> rank-n vector.shape_cast with m,n>1 was
lowered to extracts/inserts of single elements, so that a shape_cast on
a vector with N elements would always require N extracts/inserts. While
this is necessary in the worst case scenario it is sometimes possible to
use fewer, larger extracts/inserts. Specifically, the largest common
suffix on the shapes of the source and result can be extracted/inserted.
For example:

```mlir
%0 = vector.shape_cast %arg0 : vector<10x2x3xf32> to vector<2x5x2x3xf32>
```

has common suffix of shape `2x3`. Before this PR, this would be lowered
to 60 extract/insert pairs with extracts of the form
`vector.extract %arg0 [a, b, c] : f32 from vector<10x2x3xf32>`. With
this PR it is 10 extract/insert pairs with extracts of the form
`vector.extract %arg0 [a] : vector<2x3xf32> from vector<10x2x3xf32>`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list