| Issue |
240008
|
| Summary |
[mlir][Vector] `eliminate-vector-masks` crashes on rank-zero `vector.create_mask`
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
pingshiyu
|
Reproduced with the optimized LLVM Git `main` build at commit fb288ec4774f8664b165f6e302db5be8b30a41da, dated 04/Nov/2026.
```mlir
module {
func.func @rank_zero(%n: index) -> vector<i1> {
%mask = vector.create_mask %n : vector<i1>
return %mask : vector<i1>
}
}
```
```console
mlir-opt repro.mlir -o /dev/null
mlir-opt repro.mlir '--pass-pipeline=builtin.module(func.func(eliminate-vector-masks))' -o /dev/null
```
The input is valid, but the second pass crashes with:
```text
const T &llvm::ArrayRef<bool>::operator[](size_t) const [T = bool]: Assertion `Index < Length && "Invalid index!"' failed.
```
The crash also remains after canonicalization:
```console
mlir-opt repro.mlir --canonicalize -o canonicalized.mlir
mlir-opt canonicalized.mlir '--pass-pipeline=builtin.module(func.func(eliminate-vector-masks))' -o /dev/null
```
## Related cases
[Issue #132160](https://github.com/llvm/llvm-project/issues/132160) was a crash in the same transformation, but it called `function.front()` on an external bodyless function and hit an ilist sentinel assertion; [PR #173330](https://github.com/llvm/llvm-project/pull/173330) fixed that separate path. [Issue #231810](https://github.com/llvm/llvm-project/issues/231810) also mishandles a rank-zero vector, but it crashes in `foldExtractFromShuffle` while folding `vector.extract` from a rank-zero `vector.shuffle` input. [PR #236280](https://github.com/llvm/llvm-project/pull/236280) handles the special 0-D mask operand invariant in shape-cast canonicalization but does not change mask elimination. [Issue #229017](https://github.com/llvm/llvm-project/issues/229017) was a distinct semantic miscompile in `vector.shape_cast`/`vector.create_mask` canonicalization. I found no exact open or closed issue for this crash.
## LLM-Suggested Cause and Fix
[`resolveAllTrueCreateMaskOp`](https://github.com/llvm/llvm-project/blob/cba0ce818d10e4541a5f0bdc43ab8826edf45ff6/mlir/lib/Dialect/Vector/Transforms/VectorMaskElimination.cpp#L36-L84) obtains empty shape and scalable-dimension arrays from the rank-zero result type, then enumerates the one bound operand that `vector.create_mask` validly requires and indexes those arrays at position zero. The existing `CreateMaskFolder` already represents a rank-zero mask with logical shape `{1}` and scalable flags `{false}`. The elimination helper could use the same special case before checking bounds, with regression tests for dynamic and constant rank-zero masks. This is a proposed fix direction, not a tested patch.
## LLM Declaration
LLM was used to prepare the bug report, and the bug itself was found and verified by a human.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs