From e49d8b68a2330971c75ba7ff625c770e6f2ce2b9 Mon Sep 17 00:00:00 2001 From: Kyrylo Tkachov Date: Mon, 5 Jun 2017 08:46:28 +0000 Subject: [PATCH] [AArch64] Peephole for SUBS * config/aarch64/aarch64.c (define_peephole2 above *sub__): New peephole. * gcc.target/aarch64/subs_compare_1.c: New test. From-SVN: r248869 --- gcc/ChangeLog | 5 +++++ gcc/config/aarch64/aarch64.md | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ .../gcc.target/aarch64/subs_compare_1.c | 15 +++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/subs_compare_1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 037168e20c6..eb7e9ca9774 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-06-05 Kyrylo Tkachov + + * config/aarch64/aarch64.c (define_peephole2 above + *sub__): New peephole. + 2017-05-23 Jan Hubicka * config/i386/i386.c (make_resolver_func): Update. diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 93972d134b1..475c6d7e85d 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -2234,6 +2234,24 @@ [(set_attr "type" "alus_sreg")] ) +(define_peephole2 + [(set (match_operand:GPI 0 "register_operand") + (minus:GPI (match_operand:GPI 1 "aarch64_reg_or_zero") + (match_operand:GPI 2 "aarch64_reg_or_zero"))) + (set (reg:CC CC_REGNUM) + (compare:CC + (match_dup 1) + (match_dup 2)))] + "!reg_overlap_mentioned_p (operands[0], operands[1]) + && !reg_overlap_mentioned_p (operands[0], operands[2])" + [(const_int 0)] + { + emit_insn (gen_sub3_compare1 (operands[0], operands[1], + operands[2])); + DONE; + } +) + (define_insn "*sub__" [(set (match_operand:GPI 0 "register_operand" "=r") (minus:GPI (match_operand:GPI 3 "register_operand" "r") diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ef8d6389aba..027a802d04d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-05 Kyrylo Tkachov + + * gcc.target/aarch64/subs_compare_1.c: New test. + 2017-06-05 Chenghua Xu * gcc.target/mips/div-9.c: Delete duplicate test. diff --git a/gcc/testsuite/gcc.target/aarch64/subs_compare_1.c b/gcc/testsuite/gcc.target/aarch64/subs_compare_1.c new file mode 100644 index 00000000000..95c8f696fee --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/subs_compare_1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +foo (int a, int b) +{ + int x = a - b; + if (a <= b) + return x; + else + return 0; +} + +/* { dg-final { scan-assembler-times "subs\\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+" 1 } } */ +/* { dg-final { scan-assembler-not "cmp\\tw\[0-9\]+, w\[0-9\]+" } } */ -- 2.30.2