-
Notifications
You must be signed in to change notification settings - Fork 745
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
Missing optimization in Wasm for x < 0 || x > constant
#6685
Comments
x < 0 || x > constant
x < 0 || x > constant
Makes sense, those two-part comparisons look like they should be optimized. However in general we know we are missing a great deal of such patterns, and our plan has been to call out to LLVM for this in the long term. If you think these particular patterns are common and urgent to get in then I can look into it, but if this is more of a general issue then maybe instead it would make sense for us to re-prioritize the LLVM work. What do you think? OTOH the specific pattern of (module
(func $test (export "test") (param $x i32) (result i32)
(i32.ge_u
(local.get $x)
(i32.const 0)
)
)
)
$ bin/wasm-opt a.wat -O3 --print
(module
(type $0 (func (param i32) (result i32)))
(export "test" (func $test))
(func $test (param $0 i32) (result i32)
(i32.const 1)
)
) Is it possible you need to run another cycle of optimizations, if you still see that somehow? |
Would the idea be (Somewhat offtopic) where we could also benefit: Dart has only one integer type, namely The conversions between 32-bit and 64-bit come up especially when e.g. indexing arrays, getting length of arrays, ... So for example a loop over a wasm array will be using a |
Yes, that's the idea. We'd be using LLVM as a library so I don't think our compile times would be affected much (but users that want this optional feature would need to have a build of LLVM, either download it or build it).
Interesting, that does sound like an opportunity to optimize. Perhaps open a new issue specifically for that? If you can provide some complete code samples that show the situation that would be helpful too. |
…CONST` with unsigned comparison Fixes WebAssembly#6685
…CONST` with unsigned comparison Fixes WebAssembly#6685
The attached .wasm file has this code at offset 95044:
This is a direct translation of Dart code:
When optimized with
wasm-opt
765c614 (current main branch) using flagswasm-opt
generates this:Here
var0 >= 0 && var0 <= 255
part could be optimized to a single unsigned comparisonInterestingly on a different program with the exact same Dart expression, wasm-opt generates different instructions, but with the same missing optimization:
For this second program, an older wasm-opt (d844d2e) generates code with a more obvious missing optimization:
Here
ge_u
against 0 will always evaluate to 1, so the code can be simplified to the same optimized code as above.test.wasm.zip
The text was updated successfully, but these errors were encountered: