-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Arith] Support eq in detect_clip_bound #13746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,7 @@ bool DetectClipBound(const PrimExpr& cond, | |
| PostOrderVisit(cond, fvisit); | ||
| if (flag != 1) return false; | ||
| // canonical form: exp >= 0 | ||
| bool is_eq = false; | ||
| PrimExpr canonical; | ||
| if (const LTNode* op = cond.as<LTNode>()) { | ||
| if (!op->a.dtype().is_int()) return false; | ||
|
|
@@ -202,6 +203,10 @@ bool DetectClipBound(const PrimExpr& cond, | |
| } else if (const GENode* op = cond.as<GENode>()) { | ||
| if (!op->a.dtype().is_int()) return false; | ||
| canonical = op->a - op->b; | ||
| } else if (const EQNode* op = cond.as<EQNode>()) { | ||
| if (!op->a.dtype().is_int()) return false; | ||
| canonical = op->a - op->b; | ||
| is_eq = true; | ||
| } else { | ||
| return false; | ||
| } | ||
|
|
@@ -210,25 +215,40 @@ bool DetectClipBound(const PrimExpr& cond, | |
| if (!LinearEqDetector(var).Detect(canonical, &ret)) return false; | ||
| ret.coeff = analyzer.Simplify(ret.coeff); | ||
| IntervalEntry& p = (*bmap)[var.get()]; | ||
|
|
||
| Optional<PrimExpr> min_value; | ||
| Optional<PrimExpr> max_value; | ||
| if (is_const_int(ret.coeff, 1)) { | ||
| // var + shift >=0 -> var >= -shift | ||
| min_value = -ret.base; | ||
| if (is_eq) { | ||
| max_value = min_value; | ||
| } | ||
| } else if (is_const_int(ret.coeff, -1)) { | ||
| // -var + shift >=0 -> var <= shift | ||
| max_value = ret.base; | ||
| if (is_eq) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also be conditioned on
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I think of it, maybe it would be better to collect an Optional<PrimExpr> min_value = NullOpt;
Optional<PrimExpr> max_value = NullOpt;
if(is_const_int(ret.coeff, 1)) {
min_value = -ret.base;
if(is_eq) {
max_value = min_value;
}
} else if(is_const_int(ret.coeff, -1)) {
max_value = ret.base;
if(is_eq) {
min_value = max_value;
}
} |
||
| min_value = max_value; | ||
| } | ||
| } | ||
| if (!min_value.defined() && !max_value.defined()) { | ||
| return false; | ||
| } | ||
| if (min_value.defined()) { | ||
| if (p.min_value.defined()) { | ||
| p.min_value = max(p.min_value, -ret.base); | ||
| p.min_value = max(p.min_value, min_value.value()); | ||
| } else { | ||
| p.min_value = -ret.base; | ||
| p.min_value = min_value.value(); | ||
| } | ||
| return true; | ||
| } | ||
| if (is_const_int(ret.coeff, -1)) { | ||
| // -var + shift >=0 -> var <= shift | ||
| if (max_value.defined()) { | ||
| if (p.max_value.defined()) { | ||
| p.max_value = min(p.max_value, ret.base); | ||
| p.max_value = min(p.max_value, max_value.value()); | ||
| } else { | ||
| p.max_value = ret.base; | ||
| p.max_value = max_value.value(); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
| template <typename OP> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, should this have the same check for
if(!op->a.dtype().is_int())as the other cases?