Skip to content

JIT: Unnecessary jump into definitly-executed loop body #132678

Description

@BoyBaykiller

https://www.godbolt.org/z/5b594qKd5

static int Upsilon(int a, int b)
{
    int n = 100;
    while (n > 0)
    {
        int t = a + b;
        a = b;
        b = t;
        n = n - 1;
    }
    return a;
}
Program:Upsilon(int,int):int (FullOpts):
       mov      eax, 100
       jmp      SHORT G_M57122_IG04
       align    [0 bytes for IG03]
G_M57122_IG03:  ;; offset=0x0007
       mov      r8d, ecx
       mov      ecx, edx
       mov      edx, r8d
G_M57122_IG04:  ;; offset=0x000F
       add      ecx, edx
       dec      eax
       test     eax, eax
       jg       SHORT G_M57122_IG03
       mov      ecx, edx
       mov      eax, ecx
       ret      

It emits an unconditional jmp SHORT G_M57122_IG04 into the loop body at the start of the function.
Instead it could fall into it. For example, MSVC: https://godbolt.org/z/Pr5bTn999

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions