Skip to content

Conversation

@Lunderberg
Copy link
Contributor

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.


int num_outputs_used = 0;
for (bool used : usage_mask) {
num_outputs_used += used;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@slyubomirsky slyubomirsky left a 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@Lunderberg
Copy link
Contributor Author

There are quite a few components but it's clear how everything fits together.

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.
@Lunderberg Lunderberg force-pushed the unity_transform_remove_unused_outputs branch from d8c8560 to bf903a2 Compare November 29, 2023 18:26
@Lunderberg
Copy link
Contributor Author

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.

@Lunderberg Lunderberg merged commit d52a9bf into apache:unity Nov 30, 2023
@Lunderberg Lunderberg deleted the unity_transform_remove_unused_outputs branch November 30, 2023 14:18
Archermmt pushed a commit to Archermmt/tvm that referenced this pull request Dec 18, 2023
[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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants