Skip to content

[RyuJIT] Emit shrx, sarx, shlx where needed #41881

@EgorBo

Description

@EgorBo
int  Shlx(int x,  int y) => x << y;
int  Sarx(int x,  int y) => x >> y;
uint Shrx(uint x, int y) => x >> y;

Current codegen:

; Method Tests:Shlx(int,int):int
       mov      eax, ecx
       mov      ecx, edx
       shl      eax, cl
       ret      

; Method Tests:Sarx(int,int):int
       mov      eax, ecx
       mov      ecx, edx
       sar      eax, cl
       ret      

; Method Tests:Shrx(int,int):int
       mov      eax, ecx
       mov      ecx, edx
       shr      eax, cl
       ret      

Expected codegen (on a cpu with BMI2):

; Method Tests:Shlx(int,int):int
       shlx      eax, ecx, edx
       ret      

; Method Tests:Sarx(int,int):int
       sarx      eax, ecx, edx
       ret      

; Method Tests:Shrx(int,int):int
       shrx      eax, ecx, edx
       ret      

#41772 does it for rorx
godbolt: https://godbolt.org/z/8zGbYe

/cc @tannergooding

category:cq
theme:codegen
skill-level:beginner
cost:small

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions