-
Notifications
You must be signed in to change notification settings - Fork 5k
Difference of Codegen in JIT ASM when using Negation / if
-else
block code
#81479
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
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsWas playing with the JIT ASM code and found this interesting difference when using the Negation operator as compared to the public class C
{
public bool NegationOperator(bool input)
{
return !input;
}
public bool IfElseCondition(bool input)
{
if (input)
{
return false;
}
else
{
return true;
}
}
} As you can see above we are doing the same thing, in both of the code-block we are just reverting the result based on the input value. But interestingly C.NegationOperator(Boolean)
L0000: xor eax, eax
L0002: test dl, dl
L0004: sete al
L0007: ret
C.IfElseCondition(Boolean)
L0000: test dl, dl
L0002: je short L0007
L0004: xor eax, eax
L0006: ret
L0007: mov eax, 1
L000c: ret Why there is a difference in codegen!? Can't we generate the same ASM code for the
|
This is fixed in .net 8 for arm64, x64 support is coming with #81267 |
@jakobbotsch - can you close this once you verify after merging #81267? |
It is going to need a small follow-up to transform |
Was playing with the JIT ASM code and found this interesting difference when using the Negation operator as compared to the
if
andelse
block.As you can see above we are doing the same thing, in both of the code-block we are just reverting the result based on the input value.
I expect to have the same code-gen generated for both of the code blocks because we are dealing with all constants values except
input
parameters (which is technically also a constant as it can have possible 2 values only) so JIT can see that and should fold.But interestingly
if
-else
block code generates a different code than theNegationOperator
method.Sharplab link
Why there is a difference in codegen!? Can't we generate the same ASM code for the
IfElseCondition
method just like we did it forNegationOperator
method? I guess we can avoidje
instruction inIfElseCondition
.The text was updated successfully, but these errors were encountered: