hzfan commented on a change in pull request #7045:
URL: https://github.com/apache/tvm/pull/7045#discussion_r549225503
##########
File path: src/arith/canonical_simplify.cc
##########
@@ -77,6 +77,25 @@ inline PrimExpr DivImpl(PrimExpr a, PrimExpr b, DivMode
mode) {
}
}
+bool CheckCastImpl(DataType dtype, PrimExpr value, Analyzer* analyzer) {
+ if (!IsIndexType(dtype)) {
+ return false;
+ }
+ ConstIntBound bound = analyzer->const_int_bound(value);
+ int64_t ubound = Downcast<IntImm>(max_value(dtype))->value;
+ int64_t lbound = Downcast<IntImm>(min_value(dtype))->value;
+ if (value.dtype().bits() <= dtype.bits() || // upcast is safe
+ (bound->max_value <= ubound && bound->min_value >= lbound)) {
+ return true;
+ }
+ return false;
+}
+
+#define CHECK_CAST(DTYPE, VALUE) \
Review comment:
Fixed and renamed to `TVM_CHECK_CANONICAL_SIMPLIFY_CAST`. Thanks for the
suggestion!
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]