Skip to content

[AArch64] Redundant cmp not eliminated  #99390

@Kmeakin

Description

@Kmeakin

https://godbolt.org/z/av7vTE7as

#include <cstdint>
#include <numeric>

typedef uint32_t u32;

u32 midpoint_u32(u32 a, u32 b) { return std::midpoint(a, b); }

Generated code:

_Z12midpoint_u32jj:                     // @_Z12midpoint_u32jj
        cmp     w0, w1
        csel    w8, w0, w1, lo
        csel    w9, w0, w1, hi
        cmp     w0, w1
        sub     w8, w9, w8
        lsr     w8, w8, #1
        cneg    w8, w8, hi
        add     w0, w8, w0
        ret

The 2nd cmp is unnecessary: the flags register still contains the result of the first cmp instruction

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions