Skip to content

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.

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.

3 participants