From 31fd727b4d33fd4c9814e7796e5770e7643dc7c4 Mon Sep 17 00:00:00 2001 From: Georg-Johann Lay Date: Mon, 26 Sep 2011 16:55:55 +0000 Subject: [PATCH] avr.md (peephole casesi+2): Use -1 instead of 65536. * 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 | 7 +++++++ gcc/config/avr/avr.c | 31 +++++++++++++++++++++++++++++++ gcc/config/avr/avr.md | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 49e56eddd65..71a8d88d7a1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2011-09-26 Georg-Johann Lay + + * 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 * gimple-fold.c (gimplify_and_update_call_from_tree): Set diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c index da530415174..8675845fb9d 100644 --- a/gcc/config/avr/avr.c +++ b/gcc/config/avr/avr.c @@ -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. */ diff --git a/gcc/config/avr/avr.md b/gcc/config/avr/avr.md index 2efb0c4d818..790f6967482 100644 --- a/gcc/config/avr/avr.md +++ b/gcc/config/avr/avr.md @@ -4119,7 +4119,7 @@ (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)) -- 2.30.2