Skip to content

Redundant branch not being removed cleanly #127432

@hez2010

Description

@hez2010

Description

With recent jump threading opt improvements, the JIT is able to remove most branches for the following code, but there's still some leftover can be cleanup:

class Program
{
    void Test(int x)
    {
        if (x > 1)
        {
            if (x > 2)
            {
                if (x > 3)
                {
                    if (x > 4)
                    {
                        Console.WriteLine(1);
                    }
                }
            }
        }
    }
}

Codegen:

Program:Test(int):this (FullOpts):
       push     rbp
       mov      rbp, rsp
       cmp      esi, 2 ; <-- redundant branch
       jle      SHORT G_M52364_IG03
       cmp      esi, 4
       jg       SHORT G_M52364_IG04
G_M52364_IG03:  ;; offset=0x000E
       pop      rbp
       ret      
G_M52364_IG04:  ;; offset=0x0010
       mov      edi, 1
       pop      rbp
       tail.jmp [System.Console:WriteLine(int)]

Configuration

5b456ee1a58f672611dcf4a645f4c4ec5da4c996

Regression?

No

cc: @AndyAyersMS

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions