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 "tqchen (via GitHub)" <gi...@apache.org> on 2026/07/06 18:01:20 UTC

[PR] [ARITH] Scope interval constraints to mapped variables [tvm]

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

   ## Rationale
   
   Analyzer constraint scopes continue to provide loop-positive facts to constant-bound and rewrite proofs. During IntSet relaxation, however, a scoped domain constraint is a refinement only for a variable explicitly present in the relaxation map. Applying it to an unmapped variable reinterprets a free parameter as a relaxation domain and can let a loop-local symbol survive recursive interval evaluation.
   
   ## Changes
   
   - Apply scoped IntSet constraints only to variables already present in the relaxation map; unmapped variables remain free parameters.
   - Remove the finite-bound restoration fallback and its stronger parametric-bound contract.
   - Add a compact-buffer simplification regression that prevents a loop-local variable from escaping into a function-scope allocation extent.
   
   ## Validation
   
   - Positive dynamic-loop simplification
   - Compact-buffer loop-variable escape regression
   - DomainTouched finite parametric dimension
   - Deep and cyclic IntSet dependency controls
   - Ruff, ASF header, file-type, and diff checks


-- 
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] Scope interval constraints to mapped variables [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #19963:
URL: https://github.com/apache/tvm/pull/19963#discussion_r3531085274


##########
src/arith/int_set.cc:
##########
@@ -443,6 +433,13 @@ class IntervalSetEvaluator : public ExprFunctor<IntervalSet(const Expr&)> {
   IntervalSet VisitExpr_(const VarNode* op) final {
     Var var = ffi::GetRef<Var>(op);
 
+    auto it = dom_map_.find(var);
+    // Scoped constraints refine explicit relaxation domains.  Variables that
+    // are absent from dom_map_ remain free parameters of the relaxed result.
+    if (it == dom_map_.end()) {
+      return IntervalSet::SinglePoint(var.as_or_throw<PrimExpr>());

Review Comment:
   Thanks for flagging this. In the current TVM IR hierarchy, `tirx::Var` derives from the general `Expr`, not from `PrimExpr`; `tirx::PrimVar` is the checked primitive view. `IntervalSet::SinglePoint` requires a `PrimExpr`. I compiled the suggested substitution directly, and it fails with `cannot convert tvm::tirx::Var to tvm::PrimExpr`; restoring the checked cast rebuilds the compiler target successfully. Commit `adf8d6a463` intentionally moved `Var` from `PrimExpr` to `Expr` and added this exact cast. The cast is therefore required here, so I am leaving the source unchanged.



-- 
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] Scope interval constraints to mapped variables [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19963:
URL: https://github.com/apache/tvm/pull/19963#discussion_r3531067375


##########
src/arith/int_set.cc:
##########
@@ -443,6 +433,13 @@ class IntervalSetEvaluator : public ExprFunctor<IntervalSet(const Expr&)> {
   IntervalSet VisitExpr_(const VarNode* op) final {
     Var var = ffi::GetRef<Var>(op);
 
+    auto it = dom_map_.find(var);
+    // Scoped constraints refine explicit relaxation domains.  Variables that
+    // are absent from dom_map_ remain free parameters of the relaxed result.
+    if (it == dom_map_.end()) {
+      return IntervalSet::SinglePoint(var.as_or_throw<PrimExpr>());

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The cast `var.as_or_throw<PrimExpr>()` is redundant because `Var` is already a subclass of `PrimExpr` and can be implicitly converted. Removing `as_or_throw` simplifies the code and avoids an unnecessary runtime type check.
   
   ```suggestion
         return IntervalSet::SinglePoint(var);
   ```



-- 
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] Scope interval constraints to mapped variables [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #19963:
URL: https://github.com/apache/tvm/pull/19963#discussion_r3531085274


##########
src/arith/int_set.cc:
##########
@@ -443,6 +433,13 @@ class IntervalSetEvaluator : public ExprFunctor<IntervalSet(const Expr&)> {
   IntervalSet VisitExpr_(const VarNode* op) final {
     Var var = ffi::GetRef<Var>(op);
 
+    auto it = dom_map_.find(var);
+    // Scoped constraints refine explicit relaxation domains.  Variables that
+    // are absent from dom_map_ remain free parameters of the relaxed result.
+    if (it == dom_map_.end()) {
+      return IntervalSet::SinglePoint(var.as_or_throw<PrimExpr>());

Review Comment:
   Thanks for flagging this. In the current TVM IR hierarchy, `tirx::Var` derives from the general `Expr`, not from `PrimExpr`, because a variable may carry a non-primitive type. `IntervalSet::SinglePoint` requires a `PrimExpr`. I compiled the suggested substitution directly, and it fails with `cannot convert tvm::tirx::Var to tvm::PrimExpr`; restoring the checked cast rebuilds the compiler target successfully. The cast is therefore required here and also enforces the scalar invariant, so I am leaving the source unchanged.



-- 
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] Scope interval constraints to mapped variables [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #19963:
URL: 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