Skip to content

Update reference types support to latest Binaryen #1465

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 7 commits into from
Sep 19, 2020
Merged

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Sep 15, 2020

Let's see how this goes on CI :)

  • I've read the contributing guidelines

@@ -4251,14 +4250,57 @@
i32.store offset=20
local.get $0
)
(func $~lib/set/Set<u16>#find (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering what happend here. @MaxGraey any ideas why this doesn't optimize away anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just add one more monomorphized version for u16. I'm wondering could we rewrite Set#find in more sign agnostic way?

Copy link
Member

@MaxGraey MaxGraey Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I got why this happened. Before sign-extension $~lib/set/Set<u16>#find and $~lib/set/Set<i16>#find was pretty similar and folded (dedup) into one function, but with sign-extension they becomes looks pretty different and can't deduplicated anymore

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Makes sense with the signed variant now utilizing sign extension while the unsigned variant does not. Too sad that it also doesn't optimize to the same code anymore.

Comment on lines 2562 to 2551
i32.load8_u
i32.load8_s
local.get $3
i32.const 255
i32.and
i32.extend8_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's looks strange little bit. Is it correct changing load8_u to load8_s and zero-extension to sign-extension?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question. Looks like it's picking the wrong sign extension instruction indeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every unsigned load and every zero-extensions was changed to signed versions. I don't think it's correct. Is it doing by binaryen, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a Binaryen optimization doing this, at least didn't find it in the untouched file on a first glimpse. Also, the only place we are emitting i32.extend8_s is in ensureSmallIntegerWrap on Type.i8, which seems correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zero-extensions should leave as is. I don't understand why it forced always to sign-extensions

Copy link
Member

@MaxGraey MaxGraey Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However it doing only for cases like
(x & 0xFFFF) == y --> i32.extrend16_s(x) == y
i32.load16_u(...) == (y & 0xFFFF) --> i32.load16_s(...) == i32.extrend16_s(y)
which seems legit due to i32.eq / i32.ne is sign-agnostic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm: The optimization here is actually correct, so nothing to worry about?

Copy link
Member

@MaxGraey MaxGraey Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's correct in such context

@@ -27,4 +250,7 @@
i32.load8_s
drop
)
(func $~start
call $start:retain-i32
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retain-i32.optimized.wat also pretty huge regression

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this have something to do with sign extension ops not being recognized by precompute or something?

Comment on lines 15 to 19
local.tee $2
i32.extend8_s
local.get $2
i32.extend8_s
i32.ne
Copy link
Member

@MaxGraey MaxGraey Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this definitely isolate expressions from pattern matching for x != x => false case. Btw great challenge for improve binaryen in this part.

@MaxGraey
Copy link
Member

MaxGraey commented Sep 16, 2020

Could you update binaryen dep again btw?

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 16, 2020

Done, with a few fixture changes.

@MaxGraey
Copy link
Member

Yes, it was expected. Now binary expressions with float constants also canonicalized always as x op C

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 18, 2020

@MaxGraey Are there remaining issues that need to be addressed in here, or is it ok to be merged for now?

@MaxGraey
Copy link
Member

MaxGraey commented Sep 18, 2020

Could we wait for next nightly binaryen release tonight? It comes with couple optimization enhancements and I want to see how this affect for us

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 18, 2020

Sure! :)

@MaxGraey
Copy link
Member

MaxGraey commented Sep 19, 2020

Btw I'm not sure we should turn on sign-extention feature by default. Safari still doesn't support it

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 19, 2020

Hmm, the matrix looks worrying in regards to when to enable a standardized feature, and from just looking at the table it seems that the difference in features supported by Safari will only get worse.

@MaxGraey
Copy link
Member

MaxGraey commented Sep 19, 2020

Yes, that's need a discussion.
Btw could you bump binaryen here?

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 19, 2020

Disabled sign extension for now since it's not crucial, but added an agenda item for discussion to the next meeting.

@dcodeIO
Copy link
Member Author

dcodeIO commented Sep 19, 2020

Let me know if this looks good to you now :)

Copy link
Member

@MaxGraey MaxGraey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dcodeIO dcodeIO merged commit 9f38cc4 into master Sep 19, 2020
@github-actions
Copy link

🎉 This PR is included in version 0.14.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dcodeIO dcodeIO deleted the binaryen-reftypes branch June 1, 2021 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants