Skip to content

JIT suggestion: optimize comparisons of uint against int.MaxValue #37462

Open
@GrabYourPitchforks

Description

We have a few places in the code where we compare locals of type uint against int.MaxValue.

if ((uint)newSize > int.MaxValue)
{
newSize = currentLength + sizeHint;
if ((uint)newSize > int.MaxValue)

using (SafeEvpPKeyCtxHandle ctx = Interop.Crypto.EvpPKeyCtxCreate(ourKey, theirKey, out uint secretLengthU))
{
if (ctx == null || ctx.IsInvalid || secretLengthU == 0 || secretLengthU > int.MaxValue)

if (Utf8Parser.TryParse(data, out uint value, out int consumed) &&
value <= int.MaxValue &&
consumed == data.Length)

uint offset = _reader.FieldLayoutTable.GetOffset(layoutRowId);
if (offset > int.MaxValue)

There's an opportunity for a few bytes of codegen savings across these methods if the JIT treat these calls as (int)value < 0 or (int)value >= 0 instead of performing a direct comparison against the constant value 0x7FFFFFFF.

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions