[Relax] Fix divide-by-zero in reshape pattern detection#19958
[Relax] Fix divide-by-zero in reshape pattern detection#19958guan404ming wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request prevents division-by-zero crashes during reshape pattern analysis by skipping checks on blocks with zero-extent iterators, and adds a unit test to verify this behavior. The reviewer suggested using the analyzer's CanProveEqual method instead of is_zero to robustly handle symbolic zero extents as well as constant ones.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| bool has_zero_extent = std::any_of(block->iter_vars.begin(), block->iter_vars.end(), | ||
| [](const IterVar& v) { return is_zero(v->dom->extent); }); |
There was a problem hiding this comment.
Using is_zero only checks if the extent is a constant integer 0. If the extent is a symbolic expression that can be proven to be 0 by the analyzer, is_zero will return false, which could still lead to a division-by-zero crash during the subsequent inverse index map simplification.
Since the analyzer ana_ is already available, we can use this->ana_->CanProveEqual(v->dom->extent, 0) to robustly handle both constant and symbolic zero extents.
| bool has_zero_extent = std::any_of(block->iter_vars.begin(), block->iter_vars.end(), | |
| [](const IterVar& v) { return is_zero(v->dom->extent); }); | |
| bool has_zero_extent = std::any_of(block->iter_vars.begin(), block->iter_vars.end(), | |
| [this](const IterVar& v) { return this->ana_->CanProveEqual(v->dom->extent, 0); }); |
9f3ab2a to
141d4fb
Compare
141d4fb to
c0fc7be
Compare
Why
Fixes #17745.
has_reshape_patternbuilds an inverse index map that divides by each iter extent, so a zero-extent iter crashed with divide-by-zero.How
test_reshape_pattern_zero_extentintests/python/relax/test_analysis.py.