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] Refine i386 costs for widening mul


The case of widening multiplication is not handled in the
ix86_rtx_costs function.  When the multiplication is
widening, we actually do it in the inner mode.

Ok for mainline as a small patch?

Paolo

2004-02-12  Paolo Bonzini  <bonzini@gnu.org>

	* config/i386/i386.c (rtx_costs): compute correctly the
	cost of a widening multiplication.

Index: i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.646
diff -u -b -r1.646 i386.c
--- i386.c	8 Feb 2004 23:08:40 -0000	1.646
+++ i386.c	12 Feb 2004 11:23:45 -0000
@@ -15090,7 +15090,23 @@
     case MULT:
       if (FLOAT_MODE_P (mode))
 	*total = COSTS_N_INSNS (ix86_cost->fmul);
-      else if (GET_CODE (XEXP (x, 1)) == CONST_INT)
+      else
+	{
+	  rtx op0 = XEXP (x, 0);
+	  rtx op1 = XEXP (x, 1);
+
+	  /* Compute costs correctly for widening multiplication.  */
+	  if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op1) == ZERO_EXTEND)
+	      && GET_CODE (op0) == GET_CODE (op1)
+	      && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
+	         == GET_MODE_SIZE (mode))
+	    {
+	      op0 = XEXP (op0, 0);
+	      op1 = XEXP (op1, 0);
+	      mode = GET_MODE (op0);
+	    }
+
+          if (GET_CODE (op1) == CONST_INT)
 	{
 	  unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
 	  int nbits;
@@ -15106,6 +15122,7 @@
 	  /* This is arbitrary */
 	  *total = COSTS_N_INSNS (ix86_cost->mult_init[MODE_INDEX (mode)]
 			          + 7 * ix86_cost->mult_bit);
+	    }
 	}
       return false;
 


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