avr.md (peephole casesi+2): Use -1 instead of 65536.
authorGeorg-Johann Lay <avr@gjlay.de>
Mon, 26 Sep 2011 16:55:55 +0000 (16:55 +0000)
committerGeorg-Johann Lay <gjl@gcc.gnu.org>
Mon, 26 Sep 2011 16:55:55 +0000 (16:55 +0000)
* config/avr/avr.md (peephole casesi+2): Use -1 instead of 65536.
* config/avr/avr.c (avr_out_compare): Print shorter sequence for
EQ/NE comparisons against +/-1 in the case of unused-after,
non-ld-regs target.

From-SVN: r179206

gcc/ChangeLog
gcc/config/avr/avr.c
gcc/config/avr/avr.md

index 49e56eddd650999c83ce7d40ab605be10398199e..71a8d88d7a128d6f029a6d5d521c1e041e82da99 100644 (file)
@@ -1,3 +1,10 @@
+2011-09-26  Georg-Johann Lay  <avr@gjlay.de>
+
+       * config/avr/avr.md (peephole casesi+2): Use -1 instead of 65536.
+       * config/avr/avr.c (avr_out_compare): Print shorter sequence for
+       EQ/NE comparisons against +/-1 in the case of unused-after,
+       non-ld-regs target.
+
 2011-09-26  Jakub Jelinek  <jakub@redhat.com>
 
        * gimple-fold.c (gimplify_and_update_call_from_tree): Set
index da5304151744b3cb5b3f4c04343d49da0655c462..8675845fb9dad871029f501ab8c47ec1642721a8 100644 (file)
@@ -3048,6 +3048,37 @@ avr_out_compare (rtx insn, rtx *xop, int *plen)
   if (plen)
     *plen = 0;
 
+  /* Comparisons == +/-1 and != +/-1 can be done similar to camparing
+     against 0 by ORing the bytes.  This is one instruction shorter.  */
+
+  if (!test_hard_reg_class (LD_REGS, xreg)
+      && compare_eq_p (insn)
+      && reg_unused_after (insn, xreg))
+    {
+      if (xval == const1_rtx)
+        {
+          avr_asm_len ("dec %A0" CR_TAB
+                       "or %A0,%B0", xop, plen, 2);
+          
+          if (n_bytes == 4)
+            avr_asm_len ("or %A0,%C0" CR_TAB
+                         "or %A0,%D0", xop, plen, 2);
+
+          return "";
+        }
+      else if (xval == constm1_rtx)
+        {
+          if (n_bytes == 4)
+            avr_asm_len ("and %A0,%D0" CR_TAB
+                         "and %A0,%C0", xop, plen, 2);
+          
+          avr_asm_len ("and %A0,%B0" CR_TAB
+                       "com %A0", xop, plen, 2);
+          
+          return "";
+        }
+    }
+
   for (i = 0; i < n_bytes; i++)
     {
       /* We compare byte-wise.  */
index 2efb0c4d8185d60f5427106299ae59e3d9a14572..790f696748244dcb2ee92ca8e8a8b57b40ee94bd 100644 (file)
    (parallel
     [(set (cc0)
           (compare (match_dup 0)
-                  (const_int 65535)))
+                  (const_int -1)))
      (clobber (match_operand:QI 1 "d_register_operand" ""))])
    (set (pc)
        (if_then_else (ne (cc0) (const_int 0))