Skip to content

[RyuJIT][arm64] Optimize "x<0" and "x>=0" #43440

@EgorBo

Description

@EgorBo

There are two cases:

Case1:

static bool Case1(int x) => x < 0; // probably also `x >= 0`

current codegen:

    cmp     w0, #0
    cset    x0, lt

expected codegen:

    lsr     x0, w0, #31

x86-related PR: #35627

Case2 (jump condition):

static void Case2(int a)
{
    if (a < 0) // and "a >= 0"
        Foo();
}

current codegen:

    cmp     w0, #0
    bge     G_M29168_IG04

expected codegen:

    tbnz    w0, #31, G_M29168_IG04

NOTE: for the second case we already have an optimization for x==0 -> tb(n)z so should be easy to extend.

/cc @kunalspathak @echesakovMSFT

category:cq
theme:codegen
skill-level:intermediate
cost:medium
impact:medium

Metadata

Metadata

Assignees

Labels

arch-arm64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions