Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Dec 21, 2023

Avoid replacing with the exact same thing in the case of RefNull and a default
tuple.

Also be more careful with handling of numbers. Before we exited immediately
if we saw a number, but we can try to replace a number with a 0 or a 1, even
if it was a number before. That is, we consider 1 simpler than 12345678, and
0 simpler than 1.

// It's a number: try to replace it with a 0 or a 1 (trying more values
// could make sense too, but these handle most cases).
auto* c = builder->makeConst(Literal::makeZero(curr->type));
if (ExpressionAnalyzer::equal(c, curr)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use Literal::isZero or something for checking before making? (It doesn't seem to have Literal::isOne though.. Can we add it?)

Copy link
Member Author

@kripken kripken Dec 22, 2023

Choose a reason for hiding this comment

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

Good idea, yeah, we can be a little more efficient here. I did that now.

Separately, not sure if it's worth adding Literal::isOne. It would save a little code but it is rare to check that I suspect...

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

@kripken kripken merged commit 4acd476 into WebAssembly:main Jan 2, 2024
@kripken kripken deleted the reduce.better branch January 2, 2024 21:02
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
Avoid replacing with the exact same thing in the case of RefNull and a default
tuple.

Also be more careful with handling of numbers. Before we exited immediately
if we saw a number, but we can try to replace a number with a 0 or a 1, even
if it was a number before. That is, we consider 1 simpler than e.g. 12345678, and
0 simpler than 1.
@gkdn gkdn mentioned this pull request Aug 31, 2024
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