Skip to content

JIT fails to merge trivial blocks after jump threading #85547

@jakobbotsch

Description

@jakobbotsch
[MethodImpl(MethodImplOptions.NoInlining)]
private static int Foo(bool cond)
{
    int x;
    if (cond)
    {
        x = 2;
    }
    else
    {
        x = 23;
    }

    int y;
    if (cond)
    {
        y = 2;
    }
    else
    {
        y = 23;
    }

    return x + y;
}

Output:

G_M7860_IG02:  ;; offset=0000H
       test     cl, cl
       je       SHORT G_M7860_IG04
                                                ;; size=4 bbWeight=1 PerfScore 1.25
G_M7860_IG03:  ;; offset=0004H
       mov      eax, 2
       jmp      SHORT G_M7860_IG05
                                                ;; size=7 bbWeight=0.50 PerfScore 1.12
G_M7860_IG04:  ;; offset=000BH
       mov      eax, 23
       jmp      SHORT G_M7860_IG06
                                                ;; size=7 bbWeight=1 PerfScore 2.25
G_M7860_IG05:  ;; offset=0012H
       mov      edx, 2
       jmp      SHORT G_M7860_IG07
                                                ;; size=7 bbWeight=0.50 PerfScore 1.12
G_M7860_IG06:  ;; offset=0019H
       mov      edx, 23
                                                ;; size=5 bbWeight=0.50 PerfScore 0.12
G_M7860_IG07:  ;; offset=001EH
       add      eax, edx
                                                ;; size=2 bbWeight=1 PerfScore 0.25
G_M7860_IG08:  ;; offset=0020H
       ret

The blocks resulting in IG03/IG05 and IG04/IG06 should have been merged at some point to avoid those unnecessary unconditional jumps.

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