[AArch64] Fix gcc.target/aarch64/subs_compare_[12].c
commitefec48f07413fd9f84ca4cfc95c51d114e12f9f6
authorktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 Jan 2018 17:15:21 +0000 (26 17:15 +0000)
committerktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 26 Jan 2018 17:15:21 +0000 (26 17:15 +0000)
treeb12378be652ba3abf1bc63f2065dc9097005490f
parent86dc258c4df7dfb40ea8318bcd4f434e17943a67
[AArch64] Fix gcc.target/aarch64/subs_compare_[12].c

This patch fixes the testsuite failures gcc.target/aarch64/subs_compare_1.c and subs_compare_2.c
The tests check that we combine a sequence like:
        sub     w2, w0, w1
        cmp     w0, w1

into
        subs    w2, w0, w1

This is done by a couple of peepholes in aarch64.md.

Unfortunately due to scheduling and other optimisations the SUB and CMP
can come in a different order:
        cmp     w0, w1
        sub     w0, w0, w1

And the existing peepholes cannot catch that and we fail to combine the two.
This patch adds a peephole that matches the CMP as the first insn and the SUB as the second
and outputs a SUBS.  This is almost equivalent to the existing peephole that matches SUB first and CMP second
except that it doesn't have the restriction that the output register of the SUB has to not be one of the input registers.
Remember "sub w0, w0, w1 ; cmp w0, w1" is *not* equivalent to: "subs  w0, w0, w1"
but "cmp w0, w1 ; sub w0, w0, w1" is.

So this is what this patch does. It adds a peephole for the case above and one for the SUB-immediate variant
(because the SUB-immediate is represented as PLUS-of-negated-immediate and thus has different RTL structure).

Bootstrapped and tested on aarch64-none-linux-gnu.

    * config/aarch64/aarch64.md: Add peepholes for CMP + SUB -> SUBS
    and CMP + SUB-immediate -> SUBS.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257102 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/config/aarch64/aarch64.md