This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git


The following commit(s) were added to refs/heads/main by this push:
     new bed8a865f [FIX] Omit loop constraints for zero extents (#107)
bed8a865f is described below

commit bed8a865f47bf9ac382c7eb07b30577c5a882c07
Author: Tianqi Chen <[email protected]>
AuthorDate: Wed Oct 28 08:32:41 2026 -0400

    [FIX] Omit loop constraints for zero extents (#107)
    
    Skip range and positivity constraints when a loop has zero extent. This
    avoids invalid loop-variable bounds while traversing unreachable bodies
---
 src/tirx/ir/structural_constraints.cc                    |  3 ++-
 .../test_structural_visit_with_constraint_context.py     | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/tirx/ir/structural_constraints.cc 
b/src/tirx/ir/structural_constraints.cc
index 151f0888e..97d3998d0 100644
--- a/src/tirx/ir/structural_constraints.cc
+++ b/src/tirx/ir/structural_constraints.cc
@@ -61,11 +61,12 @@ ffi::Expected<void> AddLoopRange(Traversal* traversal, 
PrimVar var, PrimExpr beg
   try {
     const auto* stride = step.as<IntImmObj>();
     if (stride && stride->value > 0) {
+      PrimExpr extent = Range::GetExtentFromBeginEnd(begin, end);
+      if (prim::IsZero(extent)) return {};
       traversal->AppendConstraint(sym::RangeConstraint(var, Range(begin, 
end)));
       // These are facts at an executed positive-step loop body, not an 
assertion
       // that every RangeConstraint supplied by an arbitrary caller is 
nonempty.
       traversal->AppendConstraint(sym::PredicateConstraint(end > begin));
-      PrimExpr extent = Range::GetExtentFromBeginEnd(begin, end);
       traversal->AppendConstraint(sym::PredicateConstraint(extent > 
IntImm(extent.ty(), 0)));
     }
     return {};
diff --git a/tests/python/tirx/test_structural_visit_with_constraint_context.py 
b/tests/python/tirx/test_structural_visit_with_constraint_context.py
index b64213bf3..963760ad7 100644
--- a/tests/python/tirx/test_structural_visit_with_constraint_context.py
+++ b/tests/python/tirx/test_structural_visit_with_constraint_context.py
@@ -44,6 +44,22 @@ def test_walk_collects_binding_and_loop_range():
     assert int(loop_range.range.begin) == 0 and int(loop_range.range.extent) 
== 4
 
 
+def test_walk_omits_zero_trip_loop_constraints():
+    @T.function
+    def before():
+        for i in T.serial(0):
+            T.evaluate(T.truncmod(1, i))
+
+    collected = []
+
+    def observe(value, constraints):
+        if isinstance(value, ir.Evaluate):
+            collected.append(list(constraints))
+
+    structural.structural_walk_with_constraint_context(before.body, observe)
+    assert collected == [[]]
+
+
 def test_visit_collects_branch_predicates():
     @T.function
     def before(x: T.int32):

Reply via email to