Issue 240188
Summary [mlir][Vector] `--lower-vector-multi-reduction` silently fails without an error message
Labels mlir
Assignees
Reporter pingshiyu
    Reproduced with the optimized LLVM Git `main` build at commit fb288ec4774f8664b165f6e302db5be8b30a41da from 04/Nov/2026.

This program is valid:
```mlir
module {
  func.func @f() -> vector<1xi32> {
    %src = "" dense<1> : vector<1x9xi32>
    %acc = arith.constant dense<1> : vector<1xi32>
    %mask = vector.constant_mask [1, 1] : vector<1x9xi1>
 %result = vector.mask %mask {
      %reduced = vector.multi_reduction <or>, %src, %acc [1] : vector<1x9xi32> to vector<1xi32>
      vector.yield %reduced : vector<1xi32>
    } : vector<1x9xi1> -> vector<1xi32>
    return %result : vector<1xi32>
  }
}
```

The input verifies, but the default lowering exits 1 without any output:
```console
$ mlir-opt repro.mlir --verify-each -o /dev/null
$ echo $?
0
$ mlir-opt repro.mlir --verify-each --lower-vector-multi-reduction -o /dev/null
$ echo $?
1
```

The alternate strategy succeeds:
```console
$ mlir-opt repro.mlir --verify-each '--lower-vector-multi-reduction=lowering-strategy=inner-reduction' -o /dev/null
$ echo $?
0
```

With greedy-rewriter debugging, the default strategy ends with `The pattern rewrite did not converge after scanning 10 times`. Mixed constant masks pass until width 8 and fail from width 9 onward, all-true and all-false masks pass however. 

At the very least an error message should be produced!

## Related cases

[LLVM issue #239741](https://github.com/llvm/llvm-project/issues/239741) is a semantic canonicalization bug in which a unit-dimension masked multi-reduction returns the source instead of the accumulator. This case is distinct: canonicalization is not required, no wrong value is produced, and the default lowering fails because its greedy rewrite does not converge within the generic iteration limit.

[LLVM issue #111244](https://github.com/llvm/llvm-project/issues/111244) also mentions `--lower-vector-multi-reduction`, but its crash is in an unrelated `memref.dim` fold. This reduction has no MemRef operation.

## LLM-Suggested Cause and Fix

[`LowerVectorMultiReductionPass::runOnOperation`](https://github.com/llvm/llvm-project/blob/fb288ec4774f8664b165f6e302db5be8b30a41da/mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp#L489-L517) invokes `applyPatternsGreedily` three times with the default `GreedyRewriteConfig`, whose region-scan limit is 10. The trace reaches the extracted select chain in the unrolling phase; its constant folding exposes only one additional layer per bottom-up scan. At width 9 the tenth scan still changes the IR, so the third driver invocation returns failure and the pass calls `signalPassFailure()` without a diagnostic.

The proposed correction is to make this acyclic phase converge independently of vector width, either by changing traversal/staging so the complete chain is processed without one region scan per layer, or by deliberately using an unbounded iteration configuration after establishing termination for this rewrite set. Increasing the fixed bound would only move the failing width. This is not a tested patch. Please add a regression test using the nine-lane mixed mask above.

## 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

Reply via email to