From 770b904b37e3409ff3161000ed74f42fd7f0c6ac Mon Sep 17 00:00:00 2001
From: Salem Derisavi <33945117+derisavi-huawei@users.noreply.github.com>
Date: Wed, 13 Dec 2017 18:28:52 -0500
Subject: [PATCH] Simplify expressions early on (#702)

* Simplify expressions early on

* fixed lint errors
---
 src/arithmetic/int_set.cc | 2 +-
 src/schedule/bound.cc     | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/arithmetic/int_set.cc b/src/arithmetic/int_set.cc
index 8a88ed23e..b19aa4691 100644
--- a/src/arithmetic/int_set.cc
+++ b/src/arithmetic/int_set.cc
@@ -27,7 +27,7 @@ inline IntSet IntSet::cover_interval() const {
     for (size_t i = 0; i < s->extents.size(); ++i) {
       max = max + s->extents[i] * s->strides[i] - s->strides[i];
     }
-    return IntervalSet::make(s->base.min, max);
+    return IntervalSet::make(s->base.min, Simplify(max));
   }
   LOG(FATAL) << "cannot convert set " << (*this)->type_key() << " to interval";
   return IntSet::everything();
diff --git a/src/schedule/bound.cc b/src/schedule/bound.cc
index 203ce2870..1a06970e5 100644
--- a/src/schedule/bound.cc
+++ b/src/schedule/bound.cc
@@ -6,6 +6,7 @@
 #include <tvm/ir_visitor.h>
 #include <tvm/schedule_pass.h>
 #include <tvm/operation.h>
+#include <tvm/ir_pass.h>
 #include <unordered_map>
 #include <unordered_set>
 #include "./graph.h"
@@ -209,6 +210,10 @@ Map<IterVar, Range> InferBound(const Schedule& sch) {
       ret[iv] = iv->dom;
     }
   }
+  for (auto& p : ret) {
+    ret[p.first] = Range::make_by_min_extent(ir::Simplify(p.second->min),
+                                             ir::Simplify(p.second->extent));
+  }
   return Map<IterVar, Range>(ret.begin(), ret.end());
 }
 
-- 
GitLab