Skip to content

[Custom Descriptors] Fix exact types in RemoveUnusedBrs handling of SuccessOnlyIfNonNull #7615

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 9 commits into from
May 20, 2025

Conversation

kripken
Copy link
Member

@kripken kripken commented May 19, 2025

In that case we dropped exactness, leading to an error on the new testcase
after optimization. Fix is to use .with(Nullable).

However, it is better to skip optimization here: replacing a BrOn with another
BrOn + a RefCast is not any better. This also alters an existing test.

@kripken kripken requested a review from tlively May 19, 2025 23:51
Comment on lines 1014 to 1017
// Given the RefCast we are forced to use, we are replacing a
// BrOn* with a BrOnNonNull + a RefCast, which is never better
// than any BrOn* by itself (even BrOnCast).
return;
Copy link
Member

Choose a reason for hiding this comment

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

br_on_non_null has a couple benefits over br_on_cast: first, it takes at least three bytes less to encode (but usually more like 5 bytes less to encode) because its opcode does not have a prefix and it does not need the two heap type immediates that br_on_cast has. Even accounting for the extra two bytes and one heap type immediate required to encode the ref.cast, this is a code size savings in the usual case and a wash in the worst case. Second, splitting the cast out of the branch lets OptimizeInstructions and other passes get to it, which in principle can lead to better follow-on optimizations (although I don't know for sure that it does so).

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, but you need to add the ref.null (line 1025), adding 2 bytes. Though, maybe that can lead to optimizations..?

Copy link
Member

Choose a reason for hiding this comment

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

Good point, although, yes, I hope that would go away after follow-on optimizations. Anyway I don't feel too strongly about this (nor do I have data to support a decision). LGTM if you suspect this change will be better overall.

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, I don't feel strongly either. I flipped it to optimize, as your intuition makes sense to me.

@kripken kripken merged commit a19040d into WebAssembly:main May 20, 2025
15 checks passed
@kripken kripken deleted the exactfix branch May 20, 2025 19:17
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