-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIoptimization
Milestone
Description
JIT should be able to eliminate double negations, as far as I understand it's safe to do so for any signed integers and floats:
static float M1(float a)
{
return -(-a); // e.g. after inlining
}
static int I1(int a)
{
return -(-a);
}
/*
\--* NEG float
\--* NEG float
\--* LCL_VAR float V00 arg0
*/Current codegen:
; Method M1(float):float
G_M37219_IG01:
vzeroupper
G_M37219_IG02:
vmovss xmm1, dword ptr [reloc @RWD00]
vxorps xmm0, xmm1
vmovss xmm1, dword ptr [reloc @RWD00]
vxorps xmm0, xmm1
G_M37219_IG03:
ret
RWD00 dd 80000000h
; Total bytes of code: 28
; Method I1(int):int
G_M37095_IG01:
G_M37095_IG02:
mov eax, ecx
neg eax
neg eax
G_M37095_IG03:
ret
; Total bytes of code: 7Expected codegen:
; Method M1(float):float
G_M37219_IG01:
vzeroupper
G_M37219_IG02:
ret
; Total bytes of code: 4
; I1(int):int
G_M37095_IG01:
G_M37095_IG02:
mov eax, ecx
G_M37095_IG03:
ret
; Total bytes of code: 3A double negation might confuse the optimization introduced in dotnet/coreclr#27060
category:cq
theme:basic-cq
skill-level:beginner
cost:small
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIoptimization