Add a pass to propagate global constants to other globals#6287
Merged
kripken merged 9 commits intoWebAssembly:mainfrom Feb 8, 2024
Merged
Add a pass to propagate global constants to other globals#6287kripken merged 9 commits intoWebAssembly:mainfrom
kripken merged 9 commits intoWebAssembly:mainfrom
Conversation
tlively
approved these changes
Feb 8, 2024
| registerPass("print-stack-ir", | ||
| "print out Stack IR (useful for internal debugging)", | ||
| createPrintStackIRPass); | ||
| registerPass("propagate-globals-globally", |
Member
There was a problem hiding this comment.
Should this use registerTestPass to avoid it showing up in the --help output if it is only useful for tests? Or is it sometimes useful outside of tests as well?
Member
Author
There was a problem hiding this comment.
It is useful also for comparing stringref to imported strings.
Comment on lines
+676
to
+678
| // Apply globals to this value, which may turn it into a constant we can | ||
| // further propagate, or it may already have been one. | ||
| applyGlobals(global->init); |
Member
There was a problem hiding this comment.
This looks like a bug fix. Which test case does it affect?
Member
Author
There was a problem hiding this comment.
It's not a bugfix, see the second paragraph above: This makes us slightly more efficient in SimplifyGlobals, but we always did it.
Member
Author
There was a problem hiding this comment.
Member
|
Oops, guess I should have read the description more closely. Thanks! |
radekdoulik
pushed a commit
to dotnet/binaryen
that referenced
this pull request
Jul 12, 2024
…y#6287) SimplifyGlobals already does this, so this is a subset of that pass, and does not add anything new. It is useful for testing, however. In particular it allows testing that we propagate subsequent globals in a single pass, that is if one global reads from another and becomes constant, then it can be propagated as well. SimplifyGlobals runs multiple passes so this always worked, but with this pass we can test that we do it efficiently in one pass. This will also be useful for comparing stringref to imported strings, as it allows gathered strings to be propagated to other globals (possible with stringref, but not imported strings) but not anywhere else (which might have downsides as it could lead to more allocations). Also add an additional test for simplify-globals that we do not get confused by an unoptimizable global.get in the middle (see last part).
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.
SimplifyGlobals already does this, so this is a subset of that pass, and does not
add anything new. It is useful for testing, however.
In particular it allows testing that we propagate subsequent globals in a single
pass, that is if one global reads from another and becomes constant, then it
can be propagated as well. SimplifyGlobals runs multiple passes so this always
worked, but with this pass we can test that we do it efficiently in one pass.
This will also be useful for comparing stringref to imported strings, as it
allows gathered strings to be propagated to other globals but not anywhere
else (which might have downsides).
Also add an additional test for simplify-globals that we do not get confused by
an unoptimizable
global.getin the middle (see last part of diff) as suggestedby @tlively