[all-commits] [llvm/llvm-project] ddf9b9: [mlir][Vector] Add `vector.shuffle` tree transform...

Diego Caballero via All-commits all-commits at lists.llvm.org
Wed Jul 9 16:10:14 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ddf9b91f9fed8654c4649881f7db51f1e474701f
      https://github.com/llvm/llvm-project/commit/ddf9b91f9fed8654c4649881f7db51f1e474701f
  Author: Diego Caballero <dieg0ca6aller0 at gmail.com>
  Date:   2025-07-09 (Wed, 09 Jul 2025)

  Changed paths:
    M mlir/include/mlir/Dialect/Vector/Transforms/LoweringPatterns.h
    M mlir/include/mlir/Dialect/Vector/Transforms/Passes.h
    M mlir/include/mlir/Dialect/Vector/Transforms/Passes.td
    M mlir/lib/Dialect/Vector/Transforms/CMakeLists.txt
    A mlir/lib/Dialect/Vector/Transforms/LowerVectorToFromElementsToShuffleTree.cpp
    A mlir/test/Dialect/Vector/vector-tofrom-elements-to-shuffle-tree-transforms.mlir

  Log Message:
  -----------
  [mlir][Vector] Add `vector.shuffle` tree transformation (#145740)

This PR adds a new transformation that turns sequences of `vector.to_elements` and `vector.from_elements` into a binary tree of `vector.shuffle` operations.

(Related RFC:
https://discourse.llvm.org/t/rfc-adding-vector-to-elements-op-to-the-vector-dialect/86779).

Example:

```
  %0:4 = vector.to_elements %a : vector<4xf32>
  %1:4 = vector.to_elements %b : vector<4xf32>
  %2:4 = vector.to_elements %c : vector<4xf32>
  %3 = vector.from_elements %0#0, %0#1, %0#2, %0#3,
                            %1#0, %1#1, %1#2, %1#3,
                            %2#0, %2#1, %2#2, %2#3 : vector<12xf32>

==>

  %0 = vector.shuffle %a, %b [0, 1, 2, 3, 4, 5, 6, 7] : vector<4xf32>, vector<4xf32>
  %1 = vector.shuffle %c, %c [0, 1, 2, 3, -1, -1, -1, -1] : vector<4xf32>, vector<4xf32>
  %2 = vector.shuffle %0, %1 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : vector<8xf32>, vector<8xf32>
```

The algorithm leverages the structured extraction/insertion information
of `vector.to_elements` and `vector.from_elements` operations and builds
a set of intervals to determine the vector length that should be used at
each level of the tree to combine the level inputs in pairs.

There are a few improvements that can be implemented in the future, such
as shuffle mask compression to avoid unnecessarily large vector lengths
with poison values, but I decided to keep things "simpler" and spend
more time documenting the different steps of the algorithm so that
people can follow along.



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