llvm-project
82c7192a - [MLIR][Vector] Fix multi_reduction fold to handle empty reduction dims for any rank (#188983)

Commit
12 days ago
[MLIR][Vector] Fix multi_reduction fold to handle empty reduction dims for any rank (#188983) The fold for `vector.multi_reduction` only handled the rank-1 case with no reduction dimensions. For higher-rank vectors (e.g., `vector<2x3xf32>`) with empty reduction dims `[]`, the fold returned null, allowing `ElideUnitDimsInMultiDimReduction` to fire incorrectly. That canonicalization pattern checks that all *reduced* dims have size 1, but with zero reduction dims the check trivially passes, and the pattern then computes `acc op source` (e.g., `acc + source`) instead of the correct no-op result (`source`). This caused `--canonicalize` to produce a different value than `--lower-vector-multi-reduction` for the same program: vector.mask %m { vector.multi_reduction <add>, %src, %src [] : vector<3x3xi32> to vector<3x3xi32> } : vector<3x3xi1> -> vector<3x3xi32> * Without --lower-vector-multi-reduction: `src + src` (e.g., 2) * With --lower-vector-multi-reduction: `src` (e.g., 1) Fix the fold to return `source` for any rank when `reduction_dims` is empty. This makes the empty-dims case consistent: the operation is a noop regardless of rank, and `ElideUnitDimsInMultiDimReduction` no longer gets a chance to mishandle it. Fixes #129415 Assisted-by: Claude Code
Author
Parents
Loading