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] MIPS - Adjust cost for mult/div when optimizing for size.


When optimizing for size (-Os), the compiler often replaces a multiply
with a sequence of shifts and adds.  This is desirable for speed
optimizations, but not so when optimizing for size.
The following patch takes size into account when optimizing for size.

David.


2005-05-09  David Ung  <davidu@mips.com>

	* config/mips/mips.c (mips_rtx_costs): Adjust cost for mult/div
	when optimizing for size by reflecting the number instructions
	used instead of execution time.

Index: config/mips/mips.c
===================================================================
RCS file: /cvs/uberbaum/gcc/config/mips/mips.c,v
retrieving revision 1.502
diff -c -p -b -r1.502 mips.c
*** config/mips/mips.c	9 May 2005 11:43:48 -0000	1.502
--- config/mips/mips.c	9 May 2005 17:04:12 -0000
*************** mips_rtx_costs (rtx x, int code, int out
*** 2258,2263 ****
--- 2258,2274 ----
        return false;
  
      case MULT:
+       if (optimize_size && SCALAR_INT_MODE_P (mode))
+ 	{
+ 	  /* Reflect number of insns, not the execution time. */
+ 	  if (mode == DImode && !TARGET_64BIT)
+ 	    /* Synthesized muldi. */
+ 	    *total = COSTS_N_INSNS (9);
+ 	  else
+ 	    *total = COSTS_N_INSNS (2);
+ 	  return false;
+ 	}
+ 
  	if (mode == SFmode)
          {
            if (TUNE_MIPS3000
*************** mips_rtx_costs (rtx x, int code, int out
*** 2348,2353 ****
--- 2359,2374 ----
  
      case UDIV:
      case UMOD:
+       if (optimize_size && SCALAR_INT_MODE_P (mode))
+ 	{
+ 	  /* Reflect number of insns, not the execution time. */
+           if (TARGET_CHECK_ZERO_DIV)
+ 	    *total = COSTS_N_INSNS (5);
+ 	  else
+ 	    *total = COSTS_N_INSNS (2);
+ 	  return false;
+ 	}
+ 
        if (TUNE_MIPS3000
            || TUNE_MIPS3900)
          *total = COSTS_N_INSNS (35);



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