public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RX TARGET_RTX_COSTS function
@ 2018-02-13 15:54 Sebastian Perta
  2018-02-13 16:06 ` Oleg Endo
  0 siblings, 1 reply; 7+ messages in thread
From: Sebastian Perta @ 2018-02-13 15:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nick Clifton, 'DJ Delorie'

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.perta@renesas.com>
+
+	* config/rx/rx.c (TARGET_RTX_COSTS): Define.
+	* config/rx/rx.c (rx_rtx_costs): New function.
+
 2018-02-13  Paolo Bonzini <bonzini@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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-02-22 16:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-13 15:54 [PATCH] RX TARGET_RTX_COSTS function Sebastian Perta
2018-02-13 16:06 ` Oleg Endo
2018-02-15 14:07   ` Oleg Endo
2018-02-22 12:11     ` Oleg Endo
2018-02-22 15:41       ` Nick Clifton
2018-02-22 16:26         ` Sebastian Perta
2018-02-22 16:38         ` Oleg Endo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).