-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
JitUntriagedCLR JIT issues needing additional triageCLR JIT issues needing additional triagearea-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 SuperPMIgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorsoptimization
Milestone
Description
Noticed in https://github.com/dotnet/coreclr/issues/27917#issuecomment-557519701 We can optimize some movs away for patterns like (byte)x | (byte)y with (byte)(x | y), etc.
For example:
static int Downcast(int a, int b)
{
return (byte)a | (byte)b;
}
static long Upcast(int a, int b)
{
return (long)a & (long)b; // not only "|"
}Current codegen:
; Method Foo:Downcast(int,int):int
movzx rax, cl
movzx rdx, dl
or eax, edx
ret
; Method Foo:Upcast(int,int):long
movsxd rax, ecx
movsxd rdx, edx
and rax, rdx
ret Expected codegen (from godbolt and linux abi)
; Method Foo:Downcast(int,int):int
or edi, esi
movzx eax, dil
ret
; Method Foo:Upcast(int,int):long
and edi, esi
movsxd rax, edi
retShould be a simple optimization, e.g.:
\--* OR int
+--* CAST int <- ubyte <- int
| \--* LCL_VAR int V00 arg0
\--* CAST int <- ubyte <- int
\--* LCL_VAR int V01 arg1
To:
\--* CAST int <- ubyte <- int
\--* OR int
+--* LCL_VAR int V00 arg0
\--* LCL_VAR int V01 arg1
Also, should work for pointers:
static unsafe int DowncastPtr(int a, int b)
{
return *((byte*)&a) | *((byte*)&b);
}category:cq
theme:basic-cq
skill-level:beginner
cost:small
Symbai, itsamelambda, ForNeVeR, hughbe, sa-exe and 4 more
Metadata
Metadata
Assignees
Labels
JitUntriagedCLR JIT issues needing additional triageCLR JIT issues needing additional triagearea-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 SuperPMIgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorsoptimization