jinhongyii opened a new pull request, #19669:
URL: https://github.com/apache/tvm/pull/19669

   ## Summary
   
   `CanonicalSimplifier::Impl::VisitExpr_(LTNode)` Case 2 rewrites
   
       S + xn < 0  ⇔  S/d + xn // d < 0      where d = gcd(scales)
   
   The Case 1 derivation only works when `xn ≥ 0`. With `scale = -1` the 
equivalence becomes `≤` rather than `<`, and the rewrite silently strengthens 
the predicate by dropping the boundary `S/d == xn // d`.
   
   After CSE/inlining, a comparison such as `2*(tx%4) < 16*warp + (tx%32)//4` 
(where `row` and `col` are independent projections of the same lane id) reaches 
canonical_simplify with the divided projection on the LHS (scale = -1), and 
Case 2 folds it to a plain `0 < warp_id` — zeroing every thread that should 
have written `val` in warp 0. The same path also folds other configurations 
(e.g. `0 < (tx%32) - 8*warp`) all the way to `False`.
   
   The fix gates Case 2 with `extra->args[0]->scale == 1`. The original target 
shape (`yn % m` with positive scale and `lower_factor=1`, plus the `scale = +1 
/ lower_factor > 1` generalization) is unchanged; truly-always-true comparisons 
still fold to `True`.
   
   ## Test plan
   
   - New regression test `test_simplify_le_negative_scale_extra` in 
`tests/python/arith/test_arith_canonical_simplify.py` — asserts on simplified 
`PrimExpr`, no GPU required; pre-fix fails, post-fix passes. It also pins the 
buggy `scale = -1` shapes to their unsimplified form, confirms the `scale = +1` 
Case 2 path still optimizes, and re-asserts the truly-always-true variant still 
folds to `True`.
   - Existing `test_simplify_le` (the original Case 2 target with `scale = +1`) 
still passes.
   - `tests/python/arith/test_arith_canonical_simplify.py` — 16 passed.
   - Full `tests/python/arith/` — 932 passed (1 pre-existing flaky random-seed 
failure in `test_arith_solve_linear_equations.py` unrelated to this change, 
passes on rerun).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to