-
Notifications
You must be signed in to change notification settings - Fork 745
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
MergeBlocks: Optimize all dropped blocks #6984
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3da61e7
work
kripken ccb088c
builds
kripken 188a5d6
format
kripken 521c254
done
kripken b9187ce
work
kripken 15bf2d2
format
kripken 8799dc2
Update src/passes/MergeBlocks.cpp
kripken 6e06f33
Merge remote-tracking branch 'myself/mb.gen' into mb.gen.2
kripken e9d11ea
Merge remote-tracking branch 'origin/main' into mb.gen.2
kripken ba7f20d
simplify after feedback
kripken 09d3618
Revert "simplify after feedback"
kripken 9df0a43
test
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | ||
;; RUN: wasm-opt %s --merge-blocks -all -S -o - | filecheck %s | ||
;; | ||
;; Similar to merge-blocks.wast, but without --remove-unused-names. This tests | ||
;; the pass entirely by itself. | ||
|
||
(module | ||
;; CHECK: (func $nested-dropped-blocks (type $0) | ||
;; CHECK-NEXT: (drop | ||
;; CHECK-NEXT: (i32.const 42) | ||
;; CHECK-NEXT: ) | ||
;; CHECK-NEXT: ) | ||
(func $nested-dropped-blocks | ||
;; Fully removing unneeded blocks here requires multiple operations to happen. | ||
;; Specifically, we remove all the outer blocks first, and only then get to | ||
;; the inner named block, which we can then infer is not needed either. | ||
(block | ||
(drop | ||
(block (result i32) | ||
(block $named (result i32) | ||
(i32.const 42) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
What's the difference between the cases handled by this and this code in
optimizeBlock
?binaryen/src/passes/MergeBlocks.cpp
Line 262 in 7f30b6c
Can't all cases be handled by this new
visitDrop
?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.
The code in
optimizeBlock
runs on the children of a block, and we do need to run that more than once, unlikevisitDrop
: Each time we make a signficant change to a block, it's possible that merging with children of the block is possible, so we calloptimizeBlock
on such occasions.On the other hand, for things whose parent isn't a block, the new
visitDrop
is enough, since the parent can't be merged with it, so we can just do that once.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.
Actually, I was completely wrong here! You were right, we can remove this code. It looks like changes in the parent never lead to new improvements for the child, so we can just do the
visitDrop
part once.I'll do some fuzzing to verify this.
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, actually that was wrong, it turns out. There is at least one case where we do end up improving a child based on the parents, which I added a testcase for now (after reverting the last commit). What seems to happen is that after we optimize the parent there, we then look at the child and see that it can be removed with its name. (This was not noticed in the test suite since we run
--remove-unused-names
.)Logically I still think it makes sense that we only need the call from
visitDrop
, but that would require changes to the pass, and I'm not sure it's worth a large refactoring.