Skip to content

Conversation

@MaxGraey
Copy link
Contributor

@MaxGraey MaxGraey commented Oct 22, 2021

Canonicalize:
(signed)x > -1 ==> x >= 0
(signed)x <= -1 ==> x < 0
(signed)x < 1 ==> x <= 0
(signed)x >= 1 ==> x > 0
(unsigned)x < 1 ==> x == 0
(unsigned)x >= 1 ==> x != 0

This should helps for #4265 and other pattern matchings

@MaxGraey MaxGraey changed the title [OptimizeInstructions] Canonicalize x > -1 and x <= -1 to relational op with zero instead -1 on rhs [OptimizeInstructions] Canonicalize relational ops with near zero on rhs Oct 23, 2021
@MaxGraey
Copy link
Contributor Author

Fuzzed ITERATION: 15477

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Nice, I think this makes sense to do, and looks like on the wasm2js outputs it is already of some benefit, even.

Co-authored-by: Alon Zakai <alonzakai@gmail.com>
@kripken kripken enabled auto-merge (squash) October 26, 2021 23:01
@kripken kripken merged commit 2b24537 into WebAssembly:main Oct 26, 2021
@MaxGraey MaxGraey deleted the canon-some-relationals branch October 26, 2021 23:18
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Oct 27, 2021
We had one test (test_minimal_runtime_code_size_random_printf_wasm2js)
that was improved so much that it crossed the threshold and
was failing.

Looks like it was thanks to  WebAssembly/binaryen#4272!
sbc100 added a commit to emscripten-core/emscripten that referenced this pull request Oct 28, 2021
We had one test (test_minimal_runtime_code_size_random_printf_wasm2js)
that was improved so much that it crossed the threshold and
was failing.

Looks like it was thanks to  WebAssembly/binaryen#4272!
tlively pushed a commit that referenced this pull request Aug 27, 2022
#4282)

A continuation of #4272.

```
(signed)x  < s_min + 1   ==>   x == s_min
(signed)x >= s_min + 1   ==>   x != s_min
(signed)x  > s_max - 1   ==>   x == s_max
(signed)x <= s_max - 1   ==>   x != s_max

(unsigned)x <= u_max - 1   ==>   x != u_max
(unsigned)x  > u_max - 1   ==>   x == u_max
```
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