Skip to content

RyuJIT should optimize "X & mask" to "(type)X" #36952

@EgorBo

Description

@EgorBo

Inspired by #36920 (comment), e.g.

ulong Test(ulong x)
{
    return x & 0xFFFFFFFF; // should be optimized to "(uint)x"
}

Expected codegen:

mov      eax, edx
ret

Actual codegen:

mov      eax, 0xffffffff
and      rax, rdx
ret

Quick prototype: EgorBo@dcf81a5

Jit-diff:

Found 49 files with textual diffs.

Summary of Code Size diffs:
(Lower is better)

Total bytes of diff: -17090 (-0.03% of base)
    diff is an improvement.

Top file improvements (bytes):
      -15064 : System.Data.Common.dasm (-1.00% of base)
        -411 : Microsoft.CodeAnalysis.CSharp.dasm (-0.01% of base)
        -228 : System.Private.CoreLib.dasm (-0.00% of base)
        -149 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (-0.00% of base)
        -129 : System.Security.Cryptography.X509Certificates.dasm (-0.07% of base)
        -124 : System.Security.Cryptography.Pkcs.dasm (-0.02% of base)
        -121 : System.Private.Uri.dasm (-0.13% of base)
        -116 : Microsoft.CodeAnalysis.dasm (-0.01% of base)
        -108 : System.Runtime.Caching.dasm (-0.18% of base)
         -86 : Microsoft.VisualBasic.Core.dasm (-0.02% of base)
         -71 : System.Net.Primitives.dasm (-0.10% of base)
         -41 : Microsoft.CodeAnalysis.VisualBasic.dasm (-0.00% of base)
         -40 : System.Diagnostics.FileVersionInfo.dasm (-1.01% of base)
         -34 : System.Private.Xml.dasm (-0.00% of base)
         -28 : System.Net.Sockets.dasm (-0.01% of base)
         -23 : System.DirectoryServices.dasm (-0.01% of base)
         -23 : System.Net.NetworkInformation.dasm (-0.06% of base)
         -20 : System.Net.Http.WinHttpHandler.dasm (-0.02% of base)
         -18 : System.Diagnostics.EventLog.dasm (-0.02% of base)
         -18 : System.Drawing.Primitives.dasm (-0.05% of base)

Full log.
Most of the jit-diff comes from System.Data.RBTree1` and PMI but still looks useful IMO.

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

Metadata

Metadata

Assignees

No one assigned

    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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions