Skip to content

JIT: (bug) int.RotateLeft/RotateRight constant folding creates a non-sign-extended TYP_INT constant, so comparisons against it are folded to the wrong result #135814

Closed

Description

@EgorBo

impRotateHelper folds RotateLeft/RotateRight(const, const) for 32-bit operands via gtNewIconNode(uint32_t, baseType). When the result has bit 31 set, the TYP_INT constant holds +2147483648 instead of -2147483648, so later phases fold comparisons against it incorrectly.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

public class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static bool Test(int y) => y > int.RotateLeft(1, 31);   // == int.MinValue

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static bool TestLt(int y) => y < int.RotateLeft(1, 31);

    public static void Main()
    {
        Console.WriteLine("Test(3) = " + Test(3));
        Console.WriteLine("TestLt(3) = " + TestLt(3));
    }
}

Expected

Test(3) = True
TestLt(3) = False

Actual

Test(3) = False
TestLt(3) = True

Test is compiled to xor eax, eax and TestLt to mov eax, 1.

Regression?

Also reproduces on the 10.0.13 release (Test(3) returns False); not re-verified.

Notes

Activity

  1. added this to the 12.0.0 milestone on Oct 14, 2026
  2. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Oct 14, 2026
  3. dotnet-policy-service commented on Oct 14, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. self-assigned this
    on Oct 15, 2026
  5. added a commit that references this issue on Oct 15, 2026
    6b1cd4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions