-
-
Notifications
You must be signed in to change notification settings - Fork 672
return early #1044
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
Comments
Are you worried about |
and both versions produces the same native code: actual example: wasm-function[0]:
0x000000: ; 0x000000 from: [0x000009, 0x00001f, 0x00002c]
sub rsp, 8 ; 0x000000 48 83 ec 08
xor eax, eax ; 0x000004 33 c0
0x000006: ; 0x000006 from: [0x000028]
cmp eax, 0x20 ; 0x000006 83 f8 20
jge 0x31 ; 0x000009 0f 8d 22 00 00 00
0x00000f:
mov ecx, eax ; 0x00000f 8b c8
add ecx, 0x10 ; 0x000011 83 c1 10
movsx ecx, word ptr [r15 + rcx] ; 0x000014 41 0f bf 0c 0f
cmp ecx, 0xff ; 0x000019 81 f9 ff 00 00 00
je 0x2a ; 0x00001f 0f 84 05 00 00 00
0x000025:
add eax, 1 ; 0x000025 83 c0 01
jmp 6 ; 0x000028 eb dc
0x00002a:
xor eax, eax ; 0x00002a 33 c0
jmp 0x36 ; 0x00002c e9 05 00 00 00
0x000031:
mov eax, 1 ; 0x000031 b8 01 00 00 00
nop ; 0x000036 66 90
add rsp, 8 ; 0x000038 48 83 c4 08
ret ; 0x00003c c3 expected example: wasm-function[0]:
0x000000: ; 0x000000 from: [0x000009, 0x00001f, 0x00002c]
sub rsp, 8 ; 0x000000 48 83 ec 08
xor eax, eax ; 0x000004 33 c0
0x000006: ; 0x000006 from: [0x000028]
cmp eax, 0x20 ; 0x000006 83 f8 20
jge 0x31 ; 0x000009 0f 8d 22 00 00 00
0x00000f:
mov ecx, eax ; 0x00000f 8b c8
add ecx, 0x10 ; 0x000011 83 c1 10
movsx ecx, word ptr [r15 + rcx] ; 0x000014 41 0f bf 0c 0f
cmp ecx, 0xff ; 0x000019 81 f9 ff 00 00 00
je 0x2a ; 0x00001f 0f 84 05 00 00 00
0x000025:
add eax, 1 ; 0x000025 83 c0 01
jmp 6 ; 0x000028 eb dc
0x00002a:
xor eax, eax ; 0x00002a 33 c0
jmp 0x36 ; 0x00002c e9 05 00 00 00
0x000031:
mov eax, 1 ; 0x000031 b8 01 00 00 00
nop ; 0x000036 66 90
add rsp, 8 ; 0x000038 48 83 c4 08
ret ; 0x00003c c3 So it should have same performance |
Hi Thanks for your response.
Yes. It looks like something that could be optimized away for sake of code size.
After my explorations it is in the binary, too:
A little bit of background:
|
if you turn-off optimizations: https://webassembly.studio/?f=uwezhpittw you could see as CFG of loop's body has structure (monoblock without I don't think it's such a big deal, but if you really need smallest possible output and you're not happy with current opt stage, you can open issue at the binaryen repo. |
btw #1046 could potentially fix this problem as a side effect |
Thank you for the detailed answer. It is now optimized away by -O3. |
Hi
With the following .ts-code (simplified example)
I get
but expected something like
How can I optimise this?
The text was updated successfully, but these errors were encountered: