Skip to content
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

Improve precomputation of static instanceof #681

Merged
merged 2 commits into from Jun 21, 2019

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jun 20, 2019

This allows code like

if (expr instanceof ArrayBuffer) {
  ...
} else {
  ...
}

to statically eliminate the else branch again in the common case that expr has no side-effects (leading to just a constant instead of a block also dropping expr). This was supported before but stopped working due to being more cautious to preserve potential side-effects here.

Note that this only affects the case where static evaluation can take place, like in a downcast with known T of expr.

@dcodeIO
Copy link
Member Author

dcodeIO commented Jun 21, 2019

Last commit tries to solve this in a more general way by applying a vacuum pass prior to performing precompute. This removes any unnecessary drops and other noise without having to deal with this during codegen.

@dcodeIO
Copy link
Member Author

dcodeIO commented Jun 21, 2019

One additional optimization I came across while looking into this was be to attempt solving asserts statically where possible, not emitting any actual code. Makes some of our tests largely evaporate, like the WASI test that checks static offsets, and would allow to have static assertions in runtime code, like TLSF, that don't end up as actual code then. Not sure yet whether this deserves another builtin, like static_assert or if it's ok to make assert adapt to it. Future PR.

@dcodeIO dcodeIO changed the title Simplify static instanceof if there are no side-effects Improve precomputation of static instanceof Jun 21, 2019
@dcodeIO dcodeIO merged commit 070d67f into master Jun 21, 2019
@jtenner
Copy link
Contributor

jtenner commented Jun 21, 2019

Wow. That makes things really interesting for people who use the assert() function. Nice observation.

@dcodeIO dcodeIO deleted the instanceof-static-sideffects branch September 20, 2019 09:07
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.

None yet

2 participants