Skip to content

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

Merged
merged 8 commits into from
Sep 14, 2019
Merged

Conversation

kripken
Copy link
Member

@kripken kripken commented Sep 13, 2019

This optimizes stuff like

(global.set $x (i32.const 123))
(global.get $x)

into

(global.set $x (i32.const 123))
(i32.const 123)

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.

@kripken kripken requested a review from tlively September 13, 2019 16:50
auto* global = getModule()->getGlobal(curr->name);
assert(global->init->is<Const>());
replaceCurrent(ExpressionManipulator::copy(global->init, *getModule()));
void visitExpression(Expression* curr) {
Copy link
Member

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.

Copy link
Member Author

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",
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants