Skip to content

Commit

Permalink
Remove likelies and promises before trying to check for monotonicity. (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsharletg committed Jun 23, 2021
1 parent 2da7ca5 commit a987222
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/IROperator.cpp
Expand Up @@ -1030,6 +1030,21 @@ struct RemoveLikelies : public IRMutator {
}
};

// TODO: There could just be one IRMutator that can remove
// calls from a list. If we need more of these, it might be worth
// doing that refactor.
struct RemovePromises : public IRMutator {
using IRMutator::visit;
Expr visit(const Call *op) override {
if (op->is_intrinsic(Call::promise_clamped) ||
op->is_intrinsic(Call::unsafe_promise_clamped)) {
return mutate(op->args[0]);
} else {
return IRMutator::visit(op);
}
}
};

} // namespace

Expr remove_likelies(const Expr &e) {
Expand All @@ -1040,6 +1055,14 @@ Stmt remove_likelies(const Stmt &s) {
return RemoveLikelies().mutate(s);
}

Expr remove_promises(const Expr &e) {
return RemovePromises().mutate(e);
}

Stmt remove_promises(const Stmt &s) {
return RemovePromises().mutate(s);
}

Expr unwrap_tags(const Expr &e) {
if (const Call *tag = Call::as_tag(e)) {
return unwrap_tags(tag->args[0]);
Expand Down
8 changes: 8 additions & 0 deletions src/IROperator.h
Expand Up @@ -310,6 +310,14 @@ Expr remove_likelies(const Expr &e);
* all calls to likely() and likely_if_innermost() removed. */
Stmt remove_likelies(const Stmt &s);

/** Return an Expr that is identical to the input Expr, but with
* all calls to promise_clamped() and unsafe_promise_clamped() removed. */
Expr remove_promises(const Expr &e);

/** Return a Stmt that is identical to the input Stmt, but with
* all calls to promise_clamped() and unsafe_promise_clamped() removed. */
Stmt remove_promises(const Stmt &s);

/** If the expression is a tag helper call, remove it and return
* the tagged expression. If not, returns the expression. */
Expr unwrap_tags(const Expr &e);
Expand Down
4 changes: 3 additions & 1 deletion src/Monotonic.cpp
Expand Up @@ -631,7 +631,7 @@ ConstantInterval derivative_bounds(const Expr &e, const std::string &var, const
return ConstantInterval::everything();
}
DerivativeBounds m(var, scope);
e.accept(&m);
remove_likelies(remove_promises(e)).accept(&m);
return m.result;
}

Expand Down Expand Up @@ -726,6 +726,8 @@ void is_monotonic_test() {

check_unknown(select(x > 0, y, z));

check_increasing(select(0 < x, promise_clamped(x - 1, x - 1, z) + 1, promise_clamped(x, x, z)));

check_constant(y);

check_increasing(select(x < 17, y, y + 1));
Expand Down

0 comments on commit a987222

Please sign in to comment.