This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] arm.c: Adjust costs for the RSB instruction.


Hi,

Attached is a patch to adjust costs for the RSB instruction.

This patch teaches rtx_costs to treat a minus with a shift the same as
a minus without a shift.

Without this patch, arm-none-eabi -mcpu=cortex-a8 -O2 produces a
multiplication by 23 like so:

       mov     r3, #23
       mul     r0, r3, r0

With this patch, you get:

       add     r3, r0, r0, asl #1
       rsb     r0, r0, r3, asl #3

Some multiplications by other multipliers are also improved.

Tested on arm-none-eabi on top of the two synth_mult patches posted
recently.  OK to apply?

Kazu Hirata

2009-04-14  Kazu Hirata  <kazu@codesourcery.com>

	* config/arm/arm.c (arm_rtx_costs_1): Treat a minus with a shift
	the same as a minus without a shift.

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c	(revision 146013)
+++ gcc/config/arm/arm.c	(working copy)
@@ -5139,6 +5139,17 @@ arm_rtx_costs_1 (rtx x, enum rtx_code ou
 	  return true;
 	}
 
+      /* A shift as a part of RSB costs no more than RSB itself.  */
+      if (GET_CODE (XEXP (x, 0)) == MULT
+	  && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
+	  && ((INTVAL (XEXP (XEXP (x, 0), 1))
+	       & (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0))
+	{
+	  *total += rtx_cost (XEXP (XEXP (x, 0), 0), code, speed);
+	  *total += rtx_cost (XEXP (x, 1), code, speed);
+	  return true;
+	}
+
       if (subcode == MULT
 	  && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT
 	  && ((INTVAL (XEXP (XEXP (x, 1), 1)) &


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]