-
Notifications
You must be signed in to change notification settings - Fork 793
SimplifyGlobals: Apply known constant values in linear traces #2340
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
Conversation
auto* global = getModule()->getGlobal(curr->name); | ||
assert(global->init->is<Const>()); | ||
replaceCurrent(ExpressionManipulator::copy(global->init, *getModule())); | ||
void visitExpression(Expression* curr) { |
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.
I'm a little confused about the purpose of optimize
, since it isn't used in visitExpression
.
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 whether to optimize after doing a successful replacement. I'm adding some comments now to clarify.
@@ -267,6 +267,10 @@ void PassRegistry::registerPasses() { | |||
registerPass("simplify-globals", | |||
"miscellaneous globals-related optimizations", | |||
createSimplifyGlobalsPass); | |||
registerPass("simplify-globals-optimizing", | |||
"miscellaneous globals-related optimizations, and optimizes " | |||
"where we replaced global.gets with constants", |
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.
Maybe say "optimizes locally" or similar to indicate the difference between these additional optimizations and the baseline miscellaneous optimizations?
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.
I get the point that this could be clearer, but I'm not sure "locally" is the right term...?
This is the same as with inlining and dae - they also have text like "and optimizes where we removed/inlined/replaced" etc. Maybe we can find something better for all of them?
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, I thought optimize
was supposed to control the new linear-execution optimization. This makes more sense now. 👍
(global.set $g2 | ||
(local.get $x) | ||
) | ||
(i32.const 100) |
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.
Looks like this still got optimized.
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.
Correct, it does the optimization itself, but doesn't also run general optimization passes as a followup to that optimization.
This optimizes stuff like
into
This doesn't help much with LLVM output as it's rare to use globals (except for the stack pointer, and that's already well optimized), but it may help on general wasm. It can also help with Asyncify that does use globals extensively.