You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tlopex (via GitHub)" <gi...@apache.org> on 2026/07/02 07:01:18 UTC

[PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

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

   This PR updates `IRMutatorWithAnalyzer` and `IRVisitorWithAnalyzer` to add the constraint `loop_extent > 0` while visiting a `ForNode` body.
   
   If execution reaches the loop body, the loop must have at least one iteration, so the body context can safely assume the extent is positive. The constraint is scoped only to the loop body, leaving the loop header expressions (`min`, `extent`, `step`) outside of this assumption.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #19927:
URL: https://github.com/apache/tvm/pull/19927#issuecomment-4863215516

   cc @LeiWang1999 


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
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:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #19927:
URL: https://github.com/apache/tvm/pull/19927#issuecomment-4896940667

   a followup in https://github.com/apache/tvm/pull/19963


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19927:
URL: https://github.com/apache/tvm/pull/19927


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "LeiWang1999 (via GitHub)" <gi...@apache.org>.
LeiWang1999 commented on PR #19927:
URL: https://github.com/apache/tvm/pull/19927#issuecomment-4863251864

   cc @LJC00118


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [ARITH][TIR] Track positive loop extents in analyzer visitors [tvm]

Posted by "LJC00118 (via GitHub)" <gi...@apache.org>.
LJC00118 commented on PR #19927:
URL: https://github.com/apache/tvm/pull/19927#issuecomment-4863463020

   LGTM!


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org