Skip to content

Fix alignment tracking in VectorReduce::Add simplifier (#9100)#9104

Merged
abadams merged 2 commits intomainfrom
abadams/fix_9100
Apr 23, 2026
Merged

Fix alignment tracking in VectorReduce::Add simplifier (#9100)#9104
abadams merged 2 commits intomainfrom
abadams/fix_9100

Conversation

@abadams
Copy link
Copy Markdown
Member

@abadams abadams commented Apr 22, 2026

The bounds-and-alignment analysis for horizontal add was scaling the bounds by the reduction factor but leaving alignment untouched. For an argument whose lanes all had alignment {2, 1} (odd), the horizontal add result was still marked {2, 1}, when in fact the sum of factor odd lanes has alignment {2, factor mod 2}. A later cast would then use the stale alignment to trim [0, 1] down to a single point and fold the expression to a wrong constant.

Fix it by adding the per-lane alignment to itself factor times, which produces the right modulus (it does not shrink) and remainder. Do the same for SaturatingAdd when saturation cannot clip.

Fixes #9100

The bounds-and-alignment analysis for horizontal add was scaling the
bounds by the reduction factor but leaving alignment untouched. For an
argument whose lanes all had alignment {2, 1} (odd), the horizontal add
result was still marked {2, 1}, when in fact the sum of factor odd
lanes has alignment {2, factor mod 2}. A later cast<uint1> would then
use the stale alignment to trim [0, 1] down to a single point and
fold the expression to a wrong constant.

Fix it by adding the per-lane alignment to itself factor times, which
produces the right modulus (it does not shrink) and remainder. Do the
same for SaturatingAdd when saturation cannot clip.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@alexreinking alexreinking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please ask Claude to add a regression test for this case? It wasn't easy to find through fuzzing.

Covers the fuzzer finding that motivated 71dbcef: cast<uint1> of a
horizontal add whose lanes all have known odd alignment was being
folded to the wrong constant because the alignment was not scaled
across the reduction. Uses a select of broadcasts (which does not
match any VectorReduce::Add rewrite rule) so the check actually goes
through the info-update path rather than being constant-folded
earlier.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@abadams abadams merged commit 7c05992 into main Apr 23, 2026
23 of 24 checks passed
@alexreinking alexreinking deleted the abadams/fix_9100 branch April 23, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fuzz failure in CI involving vector reductions

2 participants