-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Unity][Transform] Implement RemoveUnusedOutputs #16117
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
[Unity][Transform] Implement RemoveUnusedOutputs #16117
Conversation
|
|
||
| int num_outputs_used = 0; | ||
| for (bool used : usage_mask) { | ||
| num_outputs_used += used; |
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.
I'm surprised you don't get a warning for this cast.
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.
IIRC, the usual automatic integer-conversion warnings occur from -Wnarrowing, which checks if there's a conversion between integer types that throws away information. Since every value that is allowed in bool can be uniquely written in int, there is no loss of information.
slyubomirsky
left a comment
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.
These changes seem to be sound. There are quite a few components but it's clear how everything fits together.
| } | ||
| } | ||
|
|
||
| Expr UnwrapBindings(Expr expr) const { |
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.
Maybe we should try to generalize some version of this logic? Similar code appears in the FNormalize PR.
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.
Good point. I think I should make a follow-up PR with all the utility functions from #15916. The ExprVisitor::UnwrapBindings utility would be good to have.
Thank you. My goal was to make it easier to test the parts in isolation, and I'm glad that worked out. I think it's also nice how each of the utility transforms can be beneficial in a general lowering pipeline, while still building together to handle the use case of 'partial tuple usage'. |
This commit implements `relax.transform.RemoveUnusedOutputs`, an extension of the current `DeadCodeElimination` pass. If an internal callee produces multiple outputs, but only some of those outputs are used, the callee can be rewritten to only produce the outputs that are used. This is intended to allow more aggressive DCE in the callee, as reducing the set of outputs can result in intermediate computations becoming unused.
d8c8560 to
bf903a2
Compare
|
I let this PR sit for a bit longer than intended, and am re-running the CI to make sure there haven't been conflicts introduced in the meantime. |
[Unity] Implement RemoveUnusedOutputs transform This commit implements `relax.transform.RemoveUnusedOutputs`, an extension of the current `DeadCodeElimination` pass. If an internal callee produces multiple outputs, but only some of those outputs are used, the callee can be rewritten to only produce the outputs that are used. This is intended to allow more aggressive DCE in the callee, as reducing the set of outputs can result in intermediate computations becoming unused.
This commit implements
relax.transform.RemoveUnusedOutputs, an extension of the currentDeadCodeEliminationpass. If an internal callee produces multiple outputs, but only some of those outputs are used, the callee can be rewritten to only produce the outputs that are used. This is intended to allow more aggressive DCE in the callee, as reducing the set of outputs can result in intermediate computations becoming unused.