DeadArgumentElimination/SignaturePruning: Prune params even if called with effects#6395
Merged
kripken merged 40 commits intoWebAssembly:mainfrom Mar 18, 2024
Merged
Conversation
Member
Author
|
Rebased after the other PR landed. |
tlively
approved these changes
Mar 14, 2024
Comment on lines
+85
to
+87
| if (operand->type == Type::unreachable) { | ||
| return Failure; | ||
| } |
Member
There was a problem hiding this comment.
We don't need the checks for call->isReturn anymore?
Member
Author
There was a problem hiding this comment.
Correct, the new logic for handling unreachable is simpler and handles it in a more general way.
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: (call $target | ||
| ;; CHECK-NEXT: (local.get $0) |
Member
There was a problem hiding this comment.
In principle we should be able to eliminate this parameter as well, since it is not used for anything except supplying itself. (i.e. the fixed point we found is not the smallest fixed point)
Member
Author
There was a problem hiding this comment.
Good point, yeah, I think we don't try to handle such recursive cases. I wonder if we're missing out because of that...
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this PR, when we saw a param was unused we sometimes could not remove it.
For example, if there was one call like this:
That nested call has effects, so we can't just remove it from the outer call - we'd need to
move it first. That motion was hard to integrate which was why it was left out, but it
turns out that is sometimes very important. E.g. in Java it is common to have such calls
that send the
thisparameter as the result of another call; not being able to remove suchparams meant we kept those nested calls alive, creating empty structs just to have
something to send there.
To fix this, this builds on top of #6394 which makes it easier to move all children out of
a parent, leaving only nested things that can be easily moved around and removed. In
more detail, DeadArgumentElimination/SignaturePruning track whether we run into effects that
prevent removing a field. If we do, then we queue an operation to move the children
out, which we do using a new utility
ParamUtils::localizeCallsTo. The pass then doesanother iteration after that operation.
Alternatively we could try to move things around immediately, but that is quite hard:
those passes already track a lot of state. It is simpler to do the fixup in an entirely
separate utility. That does come at the cost of the utility doing another pass on the
module and the pass itself running another iteration, but this situation is not the most
common.