Hello,

DJ has posted a patch a few years ago which implements TARGET_RTX_COSTS for
RX:
https://gcc.gnu.org/ml/gcc-patches/2012-05/msg00008.html

Nick has accepted the patch:
https://gcc.gnu.org/ml/gcc-patches/2012-05/msg00012.html

But it was never made it into the trunk.

The patch required some changes (the prototype, second param more exactly,
has changed) in order to compile in the trunk.
So I updated this and I also same a further change to the patch: I disabled
the replacement of the division with multiplication of reciprocals on -Os
because it increases code size for example for the following division:
int a;
void foo()
{
  a = a / 24;
}

The output code without this patch or with my updated patch it looks like:
_foo:
        mov.L   #_a, r4
        mov.L   [r4], r14
        div     #24, r14
        mov.L   r14, [r4]
        rts

While with DJ's original patch:

_foo:
        pushm   r7-r8
        mov.L   #_a, r3
        mov.L   [r3], r14
        mov.L   #0x2aaaaaab, r7
        emul    r14, r7
        shar    #2, r8, r4
        shar    #31, r14
        sub     r14, r4, r14
        mov.L   r14, [r3]
        rtsd    #8, r7-r8

Regression test is OK, I tested with the following command:
"make -k check-gcc RUNTESTFLAGS=--target_board=rx-sim"

Please let me know if this OK to check-in.

Best Regards,
Sebastian

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 257628)
+++ ChangeLog   (working copy)
@@ -1,3 +1,8 @@
+2018-02-13  Sebastian Perta  <sebastian.pe...@renesas.com>
+
+       * config/rx/rx.c (TARGET_RTX_COSTS): Define.
+       * config/rx/rx.c (rx_rtx_costs): New function.
+
 2018-02-13  Paolo Bonzini <bonz...@gnu.org>
 
        PR sanitizer/84340



Index: rx.c
===================================================================
--- rx.c        (revision 257412)
+++ rx.c        (working copy)
@@ -2975,7 +2975,73 @@
   return COSTS_N_INSNS (1);
 }
 
+#undef  TARGET_RTX_COSTS
+#define TARGET_RTX_COSTS rx_rtx_costs
+
 static bool
+rx_rtx_costs (rtx              x,
+               machine_mode mode,
+               int          outer_code ATTRIBUTE_UNUSED,
+               int          opno ATTRIBUTE_UNUSED,
+               int *        total,
+               bool         speed)
+{
+  int code = GET_CODE (x);
+
+  if((GET_CODE (x) == CONST_INT) && (INTVAL (x) == 0))
+       {
+               *total = 0;
+               return true;
+       }
+  switch (code)
+    {
+    case MULT:
+      if (mode == DImode)
+       {
+         *total = COSTS_N_INSNS (2);
+         return true;
+       }
+      /* fall through */
+    case PLUS:
+    case MINUS:
+    case AND:
+    case COMPARE:
+    case IOR:
+    case XOR:
+      if (GET_CODE (XEXP (x, 0)) == MEM
+         || GET_CODE (XEXP (x, 1)) == MEM)
+       *total = COSTS_N_INSNS (3);
+      else
+       *total = COSTS_N_INSNS (1);
+      return true;
+
+    case DIV:
+      if(speed)
+                 /* This is worst case.  */
+                 *total = COSTS_N_INSNS (20);
+      else
+                 *total = COSTS_N_INSNS (3);
+      return true;
+
+    case UDIV:
+      if(speed)
+                 /* This is worst case.  */
+                 *total = COSTS_N_INSNS (18);
+      else
+                 *total = COSTS_N_INSNS (3);
+      return true;
+
+    case IF_THEN_ELSE:
+      *total = COSTS_N_INSNS (3);
+      return true;
+
+    default:
+      break;
+    }
+  return false;
+}
+
+static bool
 rx_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
 {
   /* We can always eliminate to the frame pointer.

Reply via email to