gemini-code-assist[bot] commented on code in PR #19927:
URL: https://github.com/apache/tvm/pull/19927#discussion_r3511082469
##########
src/arith/ir_mutator_with_analyzer.cc:
##########
@@ -188,7 +188,29 @@ Stmt IRMutatorWithAnalyzer::VisitStmt_(const ForNode* op) {
Range dom = Range::FromMinExtent(op->min, op->extent);
analyzer_->Bind(op->loop_var, dom);
iter_vars_.Set(op->loop_var, dom);
- return StmtExprMutator::VisitStmt_(op);
+
+ PrimExpr min = this->VisitExpr(op->min);
+ PrimExpr extent = this->VisitExpr(op->extent);
+ ffi::Optional<PrimExpr> step{std::nullopt};
+ if (op->step.has_value()) {
+ step = this->VisitExpr(*op->step);
+ }
+ Stmt body = constraint_scope_.WithNewScope([&]() -> Stmt {
+ EnterConstraintFacts(&constraint_scope_.Current(), analyzer_,
+ op->extent > IntImm(op->extent.ty(), 0));
+ return this->VisitStmt(op->body);
+ });
Review Comment:

In `IRMutatorWithAnalyzer::VisitStmt_`, `op->extent` is visited and
potentially mutated or simplified into `extent` on line 193. If `op->extent` is
mutated (for example, if variables within it are substituted or simplified),
using the original `op->extent` in the constraint on line 200 means the
analyzer will register a constraint on the old, unsubstituted expression. As a
result, the analyzer inside the loop body won't be able to associate this
constraint with the mutated expressions in the body, rendering the constraint
ineffective. We should use the mutated `extent` instead of `op->extent` for the
constraint.
```suggestion
Stmt body = constraint_scope_.WithNewScope([&]() -> Stmt {
EnterConstraintFacts(&constraint_scope_.Current(), analyzer_,
extent > IntImm(extent.ty(), 0));
return this->VisitStmt(op->body);
});
```
--
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]