Skip to content

JIT: missing opportunity for Redundant Branch Opt #98227

Open
@EgorBo

Description

@EgorBo

A simplified repro of what I saw in a real code:

void Test(int a)
{
    if (a >= 100)
    {
        if (a <= 100)
        {
            Console.WriteLine(a);
        }
    }
}

Current codegen:

; Method Prog:Test(int):this (FullOpts)
G_M36082_IG01:
       sub      rsp, 40
G_M36082_IG02:
       cmp      edx, 100
       jl       SHORT G_M36082_IG04
G_M36082_IG03:
       cmp      edx, 100
       jg       SHORT G_M36082_IG04
       mov      ecx, edx
       call     [System.Console:WriteLine(int)]
G_M36082_IG04:
       nop      
G_M36082_IG05:
       add      rsp, 40
       ret      
; Total bytes of code: 28

Expected codegen:

; Method Prog:Test(int):this (FullOpts)
G_M36082_IG01:
       sub      rsp, 40
G_M36082_IG02:
       cmp      edx, 100
       jne      SHORT G_M36082_IG04
G_M36082_IG03:
       mov      ecx, 100
       call     [System.Console:WriteLine(int)]
G_M36082_IG04:
       nop      
G_M36082_IG05:
       add      rsp, 40
       ret      
; Total bytes of code: 26

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions