On 02/06/17 00:54, Michael Collison wrote: > This patch improves code generation for relational compares against zero that > are not merged into a subtract instruction. This patch improves the >= and < > cases. > > An example of the '<' case: > > int lt (int x, int y) > { > if ((x - y) < 0) > return 10; > > return 0; > } > > Trunk generates: > > lt: > sub w1, w0, w1 > mov w0, 10 > cmp w1, 0 > csel w0, w0, wzr, lt > ret > > With the patch we can eliminate the redundant subtract and now generate: > > lt: > cmp w0, w1 > mov w0, 10 > csel w0, w0, wzr, mi > ret > > Bootstrapped and tested on aarch64-linux-gnu. Okay for trunk? > > 2017-06-01 Michael Collison <michael.colli...@arm.com> > > * config/aarch64/aarch64-simd.md(aarch64_sub<mode>_compare0): > New pattern. > * testsuite/gcc.target/aarch64/cmp-2.c: New testcase. > >
OK. R. > pr7261.patch.patch > > > diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md > index 51368e2..b90c728 100644 > --- a/gcc/config/aarch64/aarch64.md > +++ b/gcc/config/aarch64/aarch64.md > @@ -2011,6 +2011,17 @@ > [(set_attr "type" "alus_sreg,alus_imm,alus_imm")] > ) > > +(define_insn "aarch64_sub<mode>_compare0" > + [(set (reg:CC_NZ CC_REGNUM) > + (compare:CC_NZ > + (minus:GPI (match_operand:GPI 0 "register_operand" "r") > + (match_operand:GPI 1 "aarch64_plus_operand" "r")) > + (const_int 0)))] > + "" > + "cmp\\t%<w>0, %<w>1" > + [(set_attr "type" "alus_sreg")] > +) > + > (define_insn "*compare_neg<mode>" > [(set (reg:CC_Z CC_REGNUM) > (compare:CC_Z > diff --git a/gcc/testsuite/gcc.target/aarch64/cmp-2.c > b/gcc/testsuite/gcc.target/aarch64/cmp-2.c > new file mode 100644 > index 0000000..1201664 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/cmp-2.c > @@ -0,0 +1,21 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > + > +int lt (int x, int y) > +{ > + if ((x - y) < 0) > + return 10; > + > + return 0; > +} > + > +int ge (int x, int y) > +{ > + if ((x - y) >= 0) > + return 10; > + > + return 0; > +} > + > +/* { dg-final { scan-assembler-times "csel\t" 2 } } */ > +/* { dg-final { scan-assembler-not "sub\t" } } */ >