Commit c8daec5
[Arith] Gate canonical-simplify LT Case 2 on extra scale == +1
CanonicalSimplifier::Impl::VisitExpr_(LTNode) Case 2 rewrites a
"scaled-by-d sum plus a single leftover split" comparison
S + xn < 0 <=> S/d + (xn // d) < 0 where d = gcd(scales)
into one where the leftover yn % m gets replaced by
floormod(floordiv(yn, d*L), m/(d*L)). The Case 1 derivation that
justifies dropping the remainder xn % d in [0, d) only works when
xn >= 0. With scale = -1 the equivalence becomes <= rather than <, and
the rewrite silently strengthens the predicate by dropping the boundary
case S/d == xn // d.
This surfaced as a miscompile in kernels that mask a per-lane write by
`row > col`, where `row = (lane_id // 4) + 16 * warp_id` and
`col = 2 * (lane_id % 4)` are independent projections of the same lane
id. After CSE+inlining the comparison hit canonical_simplify with the
divided projection on the LHS (scale = -1), and Case 2 folded
`2*(tx%4) < 16*warp + (tx%32)//4` into a plain `0 < warp_id`, zeroing
every thread that should have written `val` in warp 0. The same path
also folded other configurations (e.g. `0 < (tx%32) - 8*warp`) all the
way to False.
Gate Case 2 with `extra->args[0]->scale == 1`. The original target
shape (`(yn % m)` with positive scale and lower_factor=1, as well as
the scale=+1 + lower_factor>1 generalization) is unchanged; both are
covered by the existing `test_simplify_le` cases and by the new
`test_simplify_le_negative_scale_extra` regression test, which also
pins the buggy scale=-1 shape to its unsimplified form and re-asserts
that the truly-always-true `r=2` variant still folds to True.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 1240649 commit c8daec5
2 files changed
Lines changed: 53 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1419 | 1419 | | |
1420 | 1420 | | |
1421 | 1421 | | |
1422 | | - | |
| 1422 | + | |
1423 | 1423 | | |
1424 | 1424 | | |
1425 | | - | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1426 | 1433 | | |
1427 | 1434 | | |
1428 | 1435 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
493 | 537 | | |
494 | 538 | | |
0 commit comments