-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relax][Bugfix] Provide the full Expr to pattern-match rewriter #16828
[Relax][Bugfix] Provide the full Expr to pattern-match rewriter #16828
Conversation
This resolves a bug that was introduced in apache#16732. If a rewriter function returned a no-op, and the pattern-match continued, then the `matches` provided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match of `C = R.add(A,B)`, passing `C` to the rewriter instead of `R.add(A,B)`.) This bug was caused by incorrect re-wrapping of `OrPattern` in `ExprPatternRewriter`. Prior to apache#16732, all pattern-match results were populated by `ExtractMatchExpr`, and contained the result after applying `TryGetValOfVar`. When re-wrapping the result of an `OrPattern`, apache#16732 populated the additional matches with the result before applying `TryGetValOfVar`. This commit fixes the bug by applying `TryGetValOfVar`.
|
||
This is a regression test. In versions from | ||
https://github.com/apache/tvm/pull/16732 to | ||
https://github.com/apache/tvm/pull/#####, the `rewrite_call` |
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.
It's 16828 now.
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.
Thank you, and fixed!
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.
Ah, a sneaky bug. Thank you for fixing it and providing a test case.
Thank you, though @MasterJH5574 deserves credit for making the test case. That helped quite a bit in narrowing down where the bug was occurring, and was very much appreciated. |
…he#16828) * [Relax][Bugfix] Provide the full Expr to pattern-match rewriter This resolves a bug that was introduced in apache#16732. If a rewriter function returned a no-op, and the pattern-match continued, then the `matches` provided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match of `C = R.add(A,B)`, passing `C` to the rewriter instead of `R.add(A,B)`.) This bug was caused by incorrect re-wrapping of `OrPattern` in `ExprPatternRewriter`. Prior to apache#16732, all pattern-match results were populated by `ExtractMatchExpr`, and contained the result after applying `TryGetValOfVar`. When re-wrapping the result of an `OrPattern`, apache#16732 populated the additional matches with the result before applying `TryGetValOfVar`. This commit fixes the bug by applying `TryGetValOfVar`. * Update with PR link of bugfix
This resolves a bug that was introduced in #16732. If a rewriter function returned a no-op, and the pattern-match continued, then the
matches
provided to the rewriter function in subsequent calls would contain a variable to which the matched expression was bound, not the matched expression itself. (e.g. For a match ofC = R.add(A,B)
, passingC
to the rewriter instead ofR.add(A,B)
.)This bug was caused by incorrect re-wrapping of
OrPattern
inExprPatternRewriter
. Prior to #16732, all pattern-match results were populated byExtractMatchExpr
, and contained the result after applyingTryGetValOfVar
. When re-wrapping the result of anOrPattern
, #16732 populated the additional matches with the result before applyingTryGetValOfVar
. This commit fixes the bug by applyingTryGetValOfVar
.