Skip to content

Jit: Missing folding some compares in optimizebools #123291

@dhartglassMSFT

Description

@dhartglassMSFT

Code like the following (from this test) should have the eq and gt folded into GE:

    private static bool IsGreaterThanOrEqualZero(int x)
    {
        bool b = x == 0 || x > 0;
        if (b)
        {
            Console.WriteLine("IsGreaterThanOrEqualZero true");
        }
        return b;
    }

I looked at arm64 and x64 targets, and we still generate a redundant test instruction(*)

IN0001: 000005 mov      ebx, 1
IN0002: 00000A test     ecx, ecx
IN0003: 00000C setg     al
IN0004: 00000F movzx    rax, al
IN0005: 000012 test     ecx, ecx *
IN0006: 000014 cmovne   ebx, eax
IN0007: 000017 test     ebx, ebx
IN0008: 000019 je       SHORT G_M32186_IG04

I think optimizebools was supposed to get this via this pr but perhaps got regressed over a couple years.

category:cq
theme:basic-cq
skill-level:beginner
cost:small
impact:small

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions