gemini-code-assist[bot] commented on code in PR #19958:
URL: https://github.com/apache/tvm/pull/19958#discussion_r3528803098
##########
src/relax/analysis/tir_op_pattern_kind.cc:
##########
@@ -477,7 +479,11 @@ bool HasReshapePattern(const PrimFunc& func) {
nontrivial_buffer = dst_buffer_;
}
- if (nontrivial_indices.defined()) {
+ // Skip check 1 on zero-extent iters: the inverse index map would divide
by zero.
+ bool has_zero_extent = std::any_of(block->iter_vars.begin(),
block->iter_vars.end(),
+ [](const IterVar& v) { return
is_zero(v->dom->extent); });
Review 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.
```suggestion
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); });
```
--
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]