[all-commits] [llvm/llvm-project] e77155: [mlir][tensor]-Handle Dynamic Offset in BubbleUpSl...

Amir Bishara via All-commits all-commits at lists.llvm.org
Thu Feb 12 15:18:54 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e7715584c75c67468cbdbf1e48ac4c0c8b3965de
      https://github.com/llvm/llvm-project/commit/e7715584c75c67468cbdbf1e48ac4c0c8b3965de
  Author: Amir Bishara <139038766+amirBish at users.noreply.github.com>
  Date:   2026-02-13 (Fri, 13 Feb 2026)

  Changed paths:
    M mlir/include/mlir/Dialect/Tensor/Transforms/Transforms.h
    M mlir/lib/Dialect/Tensor/Transforms/ReshapePatterns.cpp
    M mlir/test/Dialect/Tensor/bubble-up-extract-slice-op.mlir

  Log Message:
  -----------
  [mlir][tensor]-Handle Dynamic Offset in BubbleUpSliceOpThroughCollapse (#178921)

This patch extends the `BubbleUpExtractSliceThroughCollapseShape`
pattern to handle cases where `tensor.extract_slice` has a dynamic
offset.

During tile and fuse transformations, it is common to encounter IR where
`tensor.extract_slice` operations appear after `tensor.collapse_shape`.
These patterns are used as cleanup transformations to canonicalize the
IR by bubbling up the slice operation before the reshape. This enables
further optimizations and simplifications downstream.

Previously, the pattern only handled:
  1. Static offsets and sizes.
  2. Dynamic sizes with a single non-unit expanded dimension.

This left a gap for additional common cases where we may have:
 - Dynamic offsets with size == 1 (single element extraction).
 - Size greater than 1 but the offset is computed dynamically.

Regarding the first case, It's always legal to perform such a
transformation.

Regarding the second case (i.e. dynamic offset with static
 size > 1) we can guarantee contiguity by more restricted
conditions:

1. The innermost expanded dimension is divisible by the slice size
(ensures the slice fits within a single "row")
2. The offset is probably a multiple of the slice size (ensures the
slice starts at an aligned boundary)

For example, given:
  - collapse_shape: tensor<6x10xf32> -> tensor<60xf32>
  - extract_slice at offset with size

If 10 % size == 0 and offset % 5 == 0, the slice is guaranteed
contiguous. The transformation delinearizes the offset to get [row, col]
indices and extracts [1, size] from the expanded 6x10 shape.

The offset divisibility check uses affine analysis to statically verify
that affine expressions (e.g., `idx * 5`) are multiples of the slice
size.



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