-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[JIT] Optimization for left-shift operator #52297
Conversation
If def DISPLAY_SIZES = 1 in jit.h, then gives and error
If def DISPLAY_SIZES = 1, gives an error
because of intersection of names "dataSize" between "compiler.h" and in "codegenarm64.cpp"
@DarkBullNull can you recheck diffs now that #53053 is done? |
Sorry for my absence. I have a term paper on the 30th, so I'm not answering yet. |
C#: [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
bool Test1(int x)
{
return ((x << 2) == 0) ? false : true;
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
bool Test2(int x, int y)
{
return ((y << 2) == x) ? false : true;
} Before all the changes: Test1:
Asm: (14 bytes)
c1e202 shl edx,2
7406 je 00007fff1363f63d
b801000000 mov eax,1
c3 ret
33c0 xor eax,eax
c3 ret
Test2:
Asm: (18 bytes)
41c1e002 shl r8d,2
443bc2 cmp r8d,edx
7406 je 00007fff13642f4f
b801000000 mov eax,1
c3 ret
33c0 xor eax,eax
c3 ret After all the changes: Test1:
Asm: (20 bytes)
8d149500000000 lea edx,[rdx*4]
85d2 test edx,edx
7406 je 00007ffef6648d01
b801000000 mov eax,1
c3 ret
33c0 xor eax,eax
c3 ret
Test2:
Asm: (23 bytes)
468d048500000000 lea r8d,[r8*4]
443bc2 cmp r8d,edx
7406 je 00007ffef664c163
b801000000 mov eax,1
c3 ret
33c0 xor eax,eax
c3 ret jit-diffs result: https://gist.github.com/DarkBullNull/011acc7a68d8e055d0e24ff973c438fa |
Did you rebase your changes? With #53214, I am seeing below code for G_M37926_IG01:
G_M37926_IG02:
shl edx, 2
je SHORT G_M37926_IG05
G_M37926_IG03:
mov eax, 1
G_M37926_IG04:
ret
G_M37926_IG05:
xor eax, eax
G_M37926_IG06:
ret
|
@kunalspathak Yes, sorry, i fixed it |
Thanks! So I see that the code size regressed more (as expected) compared to before #53214. Could you also post perfscore diffs for various collections that you posted initially? This will give an idea if the code size regression is worth considering. |
Ping @DarkBullNull |
Ping again @DarkBullNull |
@DarkBullNull - let us know if you still want to pursue this? |
With optimiz: bool Test1(int x)
{
return ((x << 2) == 0) ? false : true;
} PerfScore is 1.75 for: [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
bool Test2(int x, int y)
{
return ((y << 2) == x) ? false : true;
} Without optimiz: bool Test1(int x)
{
return ((x << 2) == 0) ? false : true;
} PerfScore is 1.75 for: [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
bool Test2(int x, int y)
{
return ((y << 2) == x) ? false : true;
} |
Thanks @DarkBullNull ...I will take a look |
Do you mind rebasing your changes on latest main? I will then double check the diffs. |
/azp run runtime-coreclr superpmi-asmdiffs |
Azure Pipelines successfully started running 1 pipeline(s). |
I inspected the asmdiffs coming out of this PR and as you pointed, the primary reason of the code size diff is coming from https://www.diffchecker.com/Yqe33Cac As such, I am not sure the savings we get from converting |
Ping. Should we pursue this PR or should I go ahead and close it? |
Oh, time to learn how to use git) Sorry me for my "Crooked PRs"
The operation "x << 2" and "x << 3" can be optimized. Just 1 quick instruction.
============(x << 2)============
Before:
After:
============(x << 3)============
Before:
After:
This will be faster than a normal left shift.
SPMI shows that there are no improvements, there are regressions. But actually, this is because "LEA REG, [REG*4]" takes up two bytes more than the shift, but this is compensated by the execution speed.