-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[TVM] Zero elimination #2634
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
[TVM] Zero elimination #2634
Changes from all commits
fb15019
1d7b561
cdd9c81
f020bf1
7f5ef4d
8c8dfb0
f697063
ea1c184
58ba0fb
cd1375e
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 |
|---|---|---|
|
|
@@ -85,6 +85,16 @@ inline const uint64_t* as_const_uint(const Expr& x) { | |
| */ | ||
| inline bool is_const_int(const Expr& x, int64_t value); | ||
|
|
||
| /*! | ||
| * \brief Check if the given expr is a const of any type equal to the given integer value. | ||
| * \param e The expression. | ||
| * \param value The value to compare to. | ||
| * \return Whether the expression is a const equal to the value. | ||
| * \tparam ValueType The value type | ||
| */ | ||
| template <typename ValueType> | ||
| inline bool is_const_value(const Expr& e, ValueType value); | ||
|
|
||
| /*! | ||
| * \brief Check whether stmt is nop. | ||
| * \param stmt The input statement | ||
|
|
@@ -503,18 +513,31 @@ inline bool is_negative_const(const Expr& a) { | |
| } | ||
| } | ||
|
|
||
| template <typename ValueType> | ||
| inline bool is_const_value(const Expr& e, ValueType value) { | ||
| static_assert(std::is_integral<ValueType>::value, | ||
| "Comparison to non-integer values is forbidden."); | ||
| // This implementation was copy-pasted from HalideIR | ||
| if (const ir::IntImm* i = e.as<ir::IntImm>()) { | ||
| return i->value == value; | ||
| } else if (const ir::UIntImm* i = e.as<ir::UIntImm>()) { | ||
| return (value >= 0) && (i->value == static_cast<uint64_t>(value)); | ||
| } else if (const ir::FloatImm* i = e.as<ir::FloatImm>()) { | ||
| return i->value == value; | ||
| } else if (const ir::Cast* c = e.as<ir::Cast>()) { | ||
| return is_const_value(c->value, value); | ||
| } else if (const ir::Broadcast* b = e.as<ir::Broadcast>()) { | ||
| return is_const_value(b->value, value); | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
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. This method's implementation is very similar to that of one difference I see is in how
Contributor
Author
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. Yes, I think it makes sense to express |
||
|
|
||
| inline bool is_const_int(const Expr& x, int64_t value) { | ||
| if (const auto* op = x.as<ir::IntImm>()) { | ||
| return op->value == value; | ||
| } else if (const auto* op = x.as<ir::UIntImm>()) { | ||
| return op->value == static_cast<uint64_t>(value); | ||
| if (x.as<ir::IntImm>() || x.as<ir::UIntImm>()) { | ||
| return is_const_value(x, value); | ||
| } else if (const auto* op = x.as<ir::Broadcast>()) { | ||
| const Expr& val = op->value; | ||
| if (const auto* opv = val.as<ir::IntImm>()) { | ||
| return opv->value == value; | ||
| } else if (const auto* opv = val.as<ir::UIntImm>()) { | ||
| return opv->value == static_cast<uint64_t>(value); | ||
| } | ||
| return !op->value.as<ir::Broadcast>() && is_const_int(op->value, value); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.