gemini-code-assist[bot] commented on code in PR #19509:
URL: https://github.com/apache/tvm/pull/19509#discussion_r3192507803
##########
src/tirx/transform/common_subexpr_elim.cc:
##########
@@ -275,6 +282,13 @@ class CSEPlanner : public StmtExprVisitor {
if (IsForbiddenNode(expr)) return false;
if (expr.as<RampNode>() || expr.as<BroadcastNode>()) return false;
if (CheckContains::ExprContains(expr, IsForbiddenNode)) return false;
+ // Reject wholly-constant expressions (no Var anywhere in the tree).
+ // BufferLoad is already filtered above by IsForbiddenNode, so
+ // "contains no Var" is sufficient to declare the expression a
+ // compile-time constant. Hoisting it adds noise; the constant
+ // folder will collapse it.
+ auto contains_var = [](const PrimExpr& e) { return e.as<VarNode>() !=
nullptr; };
+ if (!CheckContains::ExprContains(expr, contains_var)) return false;
Review Comment:

The addition of `CheckContains::ExprContains(expr, contains_var)` introduces
a second full-tree traversal for every candidate expression. Since `IsEligible`
is called for every node during the bottom-up scan, this results in $O(N^2)$
complexity in the worst case (where $N$ is the number of nodes in the
expression tree).
While this follows the existing pattern for `IsForbiddenNode`, it would be
more efficient to combine these checks into a single traversal. For example, a
single visitor could check for both forbidden nodes and the presence of
variables in one pass. Ideally, since the planner already performs a bottom-up
scan, this information could be propagated from children to parents to achieve
$O(N)$ total complexity.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]