Lunderberg commented on code in PR #13724:
URL: https://github.com/apache/tvm/pull/13724#discussion_r1065866668
##########
src/tir/transforms/lower_intrin.cc:
##########
@@ -165,21 +179,34 @@ class IntrinInjecter : public
tvm::arith::IRMutatorWithAnalyzer {
// Common pass, positive divisor
if (analyzer_->CanProveGreaterEqual(op->a, 0)) {
return truncmod(op->a, op->b);
+ }
+
+ // If the numerator's lower bound is known, express the floormod
+ // in terms of truncmod using only positive operands.
+ arith::ConstIntBound const_int_bound = analyzer_->const_int_bound(op->a);
+ if (const_int_bound->min_value != arith::ConstIntBound::kNegInf &&
+ const_int_bound->min_value < 0 &&
+ const_int_bound->min_value > -(1LL << (op->a->dtype.bits() - 1))) {
+ IntImm min(op->a->dtype, const_int_bound->min_value);
+ PrimExpr ceildiv = truncdiv(-min + (op->b - 1), op->b);
+ PrimExpr offset_numerator = analyzer_->Simplify(op->a + op->b *
ceildiv);
+ return truncmod(offset_numerator, op->b);
Review Comment:
Yup, that derivation is correct, and I've added a comment here as well.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]