Skip to content
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

Unnecessary extra and instruction in uint % 256 #8833

Closed
stephentoub opened this issue Aug 30, 2017 · 1 comment · Fixed by #79630
Closed

Unnecessary extra and instruction in uint % 256 #8833

stephentoub opened this issue Aug 30, 2017 · 1 comment · Fixed by #79630
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions optimization tenet-performance Performance related issue
Milestone

Comments

@stephentoub
Copy link
Member

Consider:

using System.Runtime.CompilerServices;

class Program
{
    static void Main()
    {
        Mod(123);
        Cast(123);
        And(123);
    }

    [MethodImpl(MethodImplOptions.NoInlining)] static byte Cast(uint i) => (byte)(i);
    [MethodImpl(MethodImplOptions.NoInlining)] static byte And(uint i) => (byte)(i & 0xFF);
    [MethodImpl(MethodImplOptions.NoInlining)] static byte Mod(uint i) => (byte)(i % 256);
}

For Cast and And I get:

       0FB6C1               movzx    rax, cl
       C3                   ret

but for Mod I get:

       81E1FF000000         and      ecx, 255
       0FB6C1               movzx    rax, cl
       C3                   ret

Is there a reason that extra and instruction needs to exist?

category:cq
theme:basic-cq
skill-level:intermediate
cost:medium

@mikedn
Copy link
Contributor

mikedn commented Aug 30, 2017

Is there a reason that extra and instruction needs to exist?

Nope.

The JIT likely detects the and+cast combination early but not mod+cast. And later mod is transformed into and but it's too late to detect the and+cast combination now.

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@TIHan TIHan removed the JitUntriaged CLR JIT issues needing additional triage label Oct 31, 2022
@TIHan TIHan self-assigned this Dec 13, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Dec 14, 2022
@JulieLeeMSFT JulieLeeMSFT modified the milestones: Future, 8.0.0 Dec 14, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions optimization tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants