[MLIR][Vector] Relax shape_cast unrolling to per-reassociation-group contiguity (#205684)
UnrollShapeCastPattern previously only unrolled a vector.shape_cast when
the target unroll tile was contiguous in the whole result vector
(isContiguous(targetShape, resultShape)). This rejected valid cases such
as:
```mlir
%0 = vector.shape_cast %src : vector<8x32xf8> to vector<8x1x32xf8> // target tile [8, 1, 4]
%1 = vector.shape_cast %src : vector<8x32x32xf8> to vector<256x32xf8> // target tile [16, 4]
```
This PR factors the source and result shapes of a shape_cast into
independent reassociation groups — maximal aligned source/result dim
ranges that hold equal element counts:
```
- 8x32 → 8x1x32 ⇒ groups {8 ↔ 8x1}, {32 ↔ 32}
- 8x32x32 → 256x32 ⇒ groups {8x32 ↔ 256}, {32 ↔ 32}
```
Instead of requiring the target tile to be contiguous in the whole
result vector, it only checks that the tile is contiguous within each
group.
This criterion is correct because a shape_cast preserves row-major
linear order. The groups partition the dimensions into blocks whose
element ranges don't overlap, so the global linear index breaks down
into one independent sub-index per group. A tile that is contiguous
within each group therefore corresponds to a slice that is contiguous
within each group of both the source and result.
Assist-by-Claude
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.