crazydemo commented on a change in pull request #9671:
URL: https://github.com/apache/tvm/pull/9671#discussion_r766298812
##########
File path: src/relay/transforms/simplify_expr.cc
##########
@@ -585,6 +585,47 @@ class EliminateIdentityRewrite : public DFPatternRewrite {
DFPattern const_;
};
+/*! \brief Make two consecutive add able to be constant_folded. */
+class SimplifyConsecutiveAdd : public DFPatternRewrite {
+ public:
+ SimplifyConsecutiveAdd() {
+ x_ = IsWildcard();
+ const1_ = IsConstant();
+ const2_ = IsConstant();
+ DFPattern add_op1_ = IsOp("add");
+ DFPattern add_op2_ = IsOp("add");
+ pattern_ = add_op2_({add_op1_({x_, const1_}), const2_});
+ }
+
+ Expr Callback(const Expr& pre, const Expr& post,
+ const Map<DFPattern, Array<Expr>>& node_map) const override {
+ const CallNode* call = pre.as<CallNode>();
+ auto x = node_map[x_][0];
+ auto c1 = node_map[const1_][0];
+ auto c2 = node_map[const2_][0];
+
+ auto pre_call = call;
+ if (pre_call->args[1].as<ConstantNode>()) {
+ pre_call = pre_call->args[0].as<CallNode>();
+ } else {
+ pre_call = pre_call->args[1].as<CallNode>();
+ }
+ // check the first two input has one non-constant
Review comment:
Thank you for your comment.
1. Unnecessary underline suffix has been removed.
2. Unnecessary `add_op` has been removed.
3. A comment saying `This pattern matching supports commutative property for
addition.` has been added.
--
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]