-
Notifications
You must be signed in to change notification settings - Fork 758
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
Add a pass to propagate global constants to other globals #6287
Conversation
@@ -369,6 +369,9 @@ void PassRegistry::registerPasses() { | |||
registerPass("print-stack-ir", | |||
"print out Stack IR (useful for internal debugging)", | |||
createPrintStackIRPass); | |||
registerPass("propagate-globals-globally", |
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.
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?
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.
It is useful also for comparing stringref to imported strings.
// 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); |
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.
This looks like a bug fix. Which test case does it affect?
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.
It's not a bugfix, see the second paragraph above: This makes us slightly more efficient in SimplifyGlobals, but we always did it.
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.
Oops, guess I should have read the description more closely. Thanks! |
…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).
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.get
in the middle (see last part of diff) as suggestedby @tlively