While this patch may leady you to think I'm about to do
something about the abysmal state of autoincdec
optimizations, I make absolutely no promises on delivering
anything to improve that state, including delivering an
analysis about that state, or even hinting about any work in
progress.  It probably won't happen, at least not from me.

-- >8 --
POST_INC is a code that's only supposed to be valid in an address, so
it should only be calculated through the TARGET_ADDRESS_COST hook, not
by the TARGET_RTX_COSTS hook.  But, because rtx_cost does not
special-case MEM costs by calling TARGET_ADDRESS_COST, we get here as
part of e.g. the auto-inc-dec and combine passes, so deal with it for
the time being.  Without this, the cost is the value of size_factor *
COSTS_N_INSNS (1), i.e. 4 per word.  There's no obvious observable
effect for generated code (coremark, libgcc and newlib-libc checked
for -march=v10), but it may make a difference in the future, so be
safe and correct the cost.

Tested at r16-6493-ge77ba7ef8c75 for cris-elf.  That the cost actually
is changed is observable mostly simply by applying -dp when compiling
 int incref(int n, char *p)
 {
   int sum = 0;

   while (n--)
     sum += *p++;

   return sum;
 }
and seeing that the cost for the single autoincrement is changed from e.g.
        adds.b [$r11+],$r10     ;# 15   [c=12 l=2]  *addsqisi_swap/1
to
        adds.b [$r11+],$r10     ;# 15   [c=8 l=2]  *addsqisi_swap/1

gcc:
        * config/cris/cris.cc (cris_rtx_costs) <POST_INC>: Handle POST_INC
        as ZERO_EXTEND and SIGN_EXTEND, i.e. as an operator without cost.
---
 gcc/config/cris/cris.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/cris/cris.cc b/gcc/config/cris/cris.cc
index f1accc0f36e5..28bc249abea0 100644
--- a/gcc/config/cris/cris.cc
+++ b/gcc/config/cris/cris.cc
@@ -2057,7 +2057,7 @@ cris_rtx_costs (rtx x, machine_mode mode, int outer_code, 
int opno,
          }
       /* fall through */
 
-    case ZERO_EXTEND: case SIGN_EXTEND:
+    case ZERO_EXTEND: case SIGN_EXTEND: case POST_INC:
       *total = rtx_cost (XEXP (x, 0), VOIDmode, (enum rtx_code) outer_code,
                         opno, speed);
       return true;
-- 
2.30.2

Reply via email to