aarch64.c (aarch64_select_cc_mode): Return CC_SWP for comparison with negated operand.
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 9 Sep 2013 13:32:50 +0000 (13:32 +0000)
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>
Mon, 9 Sep 2013 13:32:50 +0000 (13:32 +0000)
[gcc/]
2013-09-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

* config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for
comparison with negated operand.
* config/aarch64/aarch64.md (compare_neg<mode>): Match canonical RTL form.

[gcc/testsuite/]
2013-09-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

* gcc.target/aarch64/cmn-neg.c: New test.

From-SVN: r202400

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

index 228fd1bad5774bd1fca8edcd3c6aa140c07c60cb..9a94ff4b8614a2dbc425e704070d7e6823926a1e 100644 (file)
@@ -1,3 +1,9 @@
+2013-09-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * config/aarch64/aarch64.c (aarch64_select_cc_mode): Return CC_SWP for
+       comparison with negated operand.
+       * config/aarch64/aarch64.md (compare_neg<mode>): Match canonical RTL form.
+
 2013-09-09  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/58326
index 7635e1e26798664a8f5715e8522081c86923a306..d0bd38eaef02273c1bf1c637b675f5ccc1a1ca99 100644 (file)
@@ -3313,14 +3313,15 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
          || GET_CODE (x) == NEG))
     return CC_NZmode;
 
-  /* A compare with a shifted operand.  Because of canonicalization,
+  /* A compare with a shifted or negated operand.  Because of canonicalization,
      the comparison will have to be swapped when we emit the assembly
      code.  */
   if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
       && (GET_CODE (y) == REG || GET_CODE (y) == SUBREG)
       && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
          || GET_CODE (x) == LSHIFTRT
-         || GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND))
+         || GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND
+         || GET_CODE (x) == NEG))
     return CC_SWPmode;
 
   /* A compare of a mode narrower than SI mode against zero can be done
index f37f98f9994bb773785d8573a7efd1e625b5e23a..0cd7da7a3991dc1b1ffd72b06ad38f4f6898e328 100644 (file)
 )
 
 (define_insn "*compare_neg<mode>"
-  [(set (reg:CC CC_REGNUM)
-       (compare:CC
-        (match_operand:GPI 0 "register_operand" "r")
-        (neg:GPI (match_operand:GPI 1 "register_operand" "r"))))]
+  [(set (reg:CC_SWP CC_REGNUM)
+       (compare:CC_SWP
+        (neg:GPI (match_operand:GPI 0 "register_operand" "r"))
+        (match_operand:GPI 1 "register_operand" "r")))]
   ""
-  "cmn\\t%<w>0, %<w>1"
+  "cmn\\t%<w>1, %<w>0"
   [(set_attr "v8type" "alus")
    (set_attr "type" "alus_reg")
    (set_attr "mode" "<MODE>")]
index 3bb49d9bb77937a9e72b955bf5778cbcdb45f651..ffe4acb19852a8bdb503e526e7523a863a4353db 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-09  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * gcc.target/aarch64/cmn-neg.c: New test.
+
 2013-09-09  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/58326
diff --git a/gcc/testsuite/gcc.target/aarch64/cmn-neg.c b/gcc/testsuite/gcc.target/aarch64/cmn-neg.c
new file mode 100644 (file)
index 0000000..05c8bbf
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+
+extern void abort (void);
+
+void __attribute__ ((noinline))
+foo_s32 (int a, int b)
+{
+  if (a < -b)
+    abort ();
+}
+/* { dg-final { scan-assembler "cmn\tw\[0-9\]" } } */
+
+void __attribute__ ((noinline))
+foo_s64 (long long a, long long b)
+{
+  if (a < -b)
+    abort ();
+}
+/* { dg-final { scan-assembler "cmn\tx\[0-9\]" } } */
+
+
+int
+main (void)
+{
+  int a = 30;
+  int b = 42;
+  foo_s32 (a, b);
+  foo_s64 (a, b);
+  return 0;
+}
+
+/* { dg-final { cleanup-saved-temps } } */