Skip to content

[AArch64] Optimize compares with multiple uses #59598

@SamTebbs33

Description

@SamTebbs33

This example has multiple uses on the AND:

int and(int num) {
    num = num & 0xff;
    if (num > 1)
        return call(num)+1;
    return 0;
}

and becomes

        and     w0, w0, #0xff
        cmp     w0, #2
        b.lo    .LBB1_2

If this example used a tst it could start a cycle earlier, not having to wait for the result of the and, like in

int tst(int num) {
    num = num & 0xff;
    if (num > 1)
        return call(0)+1;
    return 0;
}

which becomes

        tst     w0, #0xfe
        b.eq    .LBB0_2

https://godbolt.org/z/6Tnz4szYn

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