[AArch64] Peephole for SUBS
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 5 Jun 2017 08:46:28 +0000 (08:46 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Mon, 5 Jun 2017 08:46:28 +0000 (08:46 +0000)
* config/aarch64/aarch64.c (define_peephole2 above
*sub_<shift>_<mode>): New peephole.

* gcc.target/aarch64/subs_compare_1.c: New test.

From-SVN: r248869

gcc/ChangeLog
gcc/config/aarch64/aarch64.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/aarch64/subs_compare_1.c [new file with mode: 0644]

index 037168e20c61e648880971921dfec714c7583919..eb7e9ca97744363cc7d42bd11b5ca059466883ff 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-05  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * config/aarch64/aarch64.c (define_peephole2 above
+       *sub_<shift>_<mode>): New peephole.
+
 2017-05-23  Jan Hubicka  <hubicka@ucw.cz>
 
        * config/i386/i386.c (make_resolver_func): Update.
index 93972d134b1eeba0e339f00528fc2e03f0c02052..475c6d7e85dd7a445ff9d757c246343b8f88e620 100644 (file)
   [(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_sub<mode>3_compare1 (operands[0], operands[1],
+                                        operands[2]));
+    DONE;
+  }
+)
+
 (define_insn "*sub_<shift>_<mode>"
   [(set (match_operand:GPI 0 "register_operand" "=r")
        (minus:GPI (match_operand:GPI 3 "register_operand" "r")
index ef8d6389aba68cf1b1d1ea8e14fa0454cece7d2a..027a802d04df497ba71782f0cc6873d7c6e10df8 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-05  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * gcc.target/aarch64/subs_compare_1.c: New test.
+
 2017-06-05  Chenghua Xu  <paul.hua.gm@gmail.com>
 
        * 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 (file)
index 0000000..95c8f69
--- /dev/null
@@ -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\]+" } } */