aarch64.c (aarch64_select_cc_mode): Allow NEG code in CC_NZ mode.
authorNaveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
Fri, 12 Apr 2013 04:19:14 +0000 (04:19 +0000)
committerNaveen H.S <naveenh@gcc.gnu.org>
Fri, 12 Apr 2013 04:19:14 +0000 (04:19 +0000)
gcc

2013-04-10   Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

* config/aarch64/aarch64.c (aarch64_select_cc_mode): Allow NEG
code in CC_NZ mode.
* config/aarch64/aarch64.md (*neg_<shift><mode>3_compare0): New
pattern.

gcc/testsuite

2013-04-10   Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

* gcc.target/aarch64/negs.c: New.

From-SVN: r197838

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

index ef5560b871448070dcebe9f1a2e60cb408d221c7..208fc23df26b48a842046b31ad40546c96d68c73 100644 (file)
@@ -1,3 +1,10 @@
+2013-04-11   Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
+
+       * config/aarch64/aarch64.c (aarch64_select_cc_mode): Allow NEG
+       code in CC_NZ mode.
+       * config/aarch64/aarch64.md (*neg_<shift><mode>3_compare0): New
+       pattern.
+
 2013-04-11  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/48184
index 49016c10adfccde094d461d0ff37e21b40bb7620..68f847a2977cc3b12da69cad117fb8241a8b71bb 100644 (file)
@@ -3087,7 +3087,8 @@ aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
   if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
       && y == const0_rtx
       && (code == EQ || code == NE || code == LT || code == GE)
-      && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS || GET_CODE (x) == AND))
+      && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS || GET_CODE (x) == AND
+         || GET_CODE (x) == NEG))
     return CC_NZmode;
 
   /* A compare with a shifted operand.  Because of canonicalization,
index 2533145b94b18b954f29ae48b444d8992fbf04c1..dab5b40d59f122db70b9679ff2b176d3a0b5259d 100644 (file)
    (set_attr "mode" "SI")]
 )
 
+(define_insn "*neg_<shift><mode>3_compare0"
+  [(set (reg:CC_NZ CC_REGNUM)
+       (compare:CC_NZ
+        (neg:GPI (ASHIFT:GPI
+                  (match_operand:GPI 1 "register_operand" "r")
+                  (match_operand:QI 2 "aarch64_shift_imm_<mode>" "n")))
+        (const_int 0)))
+   (set (match_operand:GPI 0 "register_operand" "=r")
+       (neg:GPI (ASHIFT:GPI (match_dup 1) (match_dup 2))))]
+  ""
+  "negs\\t%<w>0, %<w>1, <shift> %2"
+  [(set_attr "v8type" "alus_shift")
+   (set_attr "mode" "<MODE>")]
+)
+
 (define_insn "*neg_<shift>_<mode>2"
   [(set (match_operand:GPI 0 "register_operand" "=r")
        (neg:GPI (ASHIFT:GPI
index a3a517e177e843ee6b4aa6185c3915a036772085..4ee12e84ed89948b99710434571f418a2dea3649 100644 (file)
@@ -1,3 +1,7 @@
+2013-04-11   Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
+
+       * gcc.target/aarch64/negs.c: New.
+
 2013-04-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/56895
diff --git a/gcc/testsuite/gcc.target/aarch64/negs.c b/gcc/testsuite/gcc.target/aarch64/negs.c
new file mode 100644 (file)
index 0000000..1c23041
--- /dev/null
@@ -0,0 +1,108 @@
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps" } */
+
+extern void abort (void);
+int z;
+
+int
+negs_si_test1 (int a, int b, int c)
+{
+  int d = -b;
+
+  /* { dg-final { scan-assembler "negs\tw\[0-9\]+, w\[0-9\]+" } } */
+  if (d < 0)
+    return a + c;
+
+  z = d;
+    return b + c + d;
+}
+
+int
+negs_si_test3 (int a, int b, int c)
+{
+  int d = -(b) << 3;
+
+  /* { dg-final { scan-assembler "negs\tw\[0-9\]+, w\[0-9\]+, lsl 3" } } */
+  if (d == 0)
+    return a + c;
+
+  z = d;
+    return b + c + d;
+}
+
+typedef long long s64;
+s64 zz;
+
+s64
+negs_di_test1 (s64 a, s64 b, s64 c)
+{
+  s64 d = -b;
+
+  /* { dg-final { scan-assembler "negs\tx\[0-9\]+, x\[0-9\]+" } } */
+  if (d < 0)
+    return a + c;
+
+  zz = d;
+    return b + c + d;
+}
+
+s64
+negs_di_test3 (s64 a, s64 b, s64 c)
+{
+  s64 d = -(b) << 3;
+
+  /* { dg-final { scan-assembler "negs\tx\[0-9\]+, x\[0-9\]+, lsl 3" } } */
+  if (d == 0)
+    return a + c;
+
+  zz = d;
+    return b + c + d;
+}
+
+int main ()
+{
+  int x;
+  s64 y;
+
+  x = negs_si_test1 (2, 12, 5);
+  if (x != 7)
+    abort ();
+
+  x = negs_si_test1 (1, 2, 32);
+  if (x != 33)
+    abort ();
+
+  x = negs_si_test3 (13, 14, 5);
+  if (x != -93)
+    abort ();
+
+  x = negs_si_test3 (15, 21, 2);
+  if (x != -145)
+    abort ();
+
+  y = negs_di_test1 (0x20202020ll,
+                    0x65161611ll,
+                    0x42434243ll);
+  if (y != 0x62636263ll)
+    abort ();
+
+  y = negs_di_test1 (0x1010101010101ll,
+                    0x123456789abcdll,
+                    0x5555555555555ll);
+  if (y != 0x6565656565656ll)
+    abort ();
+
+  y = negs_di_test3 (0x62523781ll,
+                    0x64234978ll,
+                    0x12345123ll);
+  if (y != 0xfffffffd553d4edbll)
+    abort ();
+
+  y = negs_di_test3 (0x763526268ll,
+                    0x101010101ll,
+                    0x222222222ll);
+  if (y != 0xfffffffb1b1b1b1bll)
+    abort ();
+
+  return 0;
+}