Skip to content

[InstCombine] Missing fold for (1 + 2 * a * b > 0) ? a : a * b --> a * b < 0 ? a * b : a #61538

@k-arrows

Description

@k-arrows

Test code:

int foo(int a, int b)
{
    return (1 + 2 * a * b > 0) ? a : a * b ;
}

clang

foo(int, int):                               // @foo(int, int)
        mul     w8, w0, w1
        mov     w9, #1                          // =0x1
        orr     w8, w9, w8, lsl #1
        cmp     w8, #1
        csinc   w8, w1, wzr, lt
        mul     w0, w8, w0
        ret

gcc

foo(int, int):
        mul     w1, w0, w1
        cmp     w1, 0
        csel    w0, w1, w0, lt
        ret

https://godbolt.org/z/b79ehqG77

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions