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]

[Committed] Change choose_multiplier to return an rtx


This clean-up is the second step towards resolving PR middle-end/17958.
See http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01692.html  This part
changes expmed.c's choose_multiplier API to return an rtx instead of an
unsigned HOST_WIDE_INT for the chosen multiplier lowpart.  This tidies
up most of the callers that need to pass an rtx to expand_mult_highpart.


The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures.

Committed to mainline CVS.


2005-01-24  Roger Sayle  <roger@eyesopen.com>

	* expmed.c (choose_multiplier): Change interface to return the
	multiplier lowpart as an rtx instead of an unsigned HOST_WIDE_INT.
	(expand_divmod): Update calls to choose_multiplier.


Index: expmed.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expmed.c,v
retrieving revision 1.215
diff -c -3 -p -r1.215 expmed.c
*** expmed.c	24 Jan 2005 02:28:14 -0000	1.215
--- expmed.c	24 Jan 2005 18:23:23 -0000
*************** static bool choose_mult_variant (enum ma
*** 2385,2392 ****
  static rtx expand_mult_const (enum machine_mode, rtx, HOST_WIDE_INT, rtx,
  			      const struct algorithm *, enum mult_variant);
  static unsigned HOST_WIDE_INT choose_multiplier (unsigned HOST_WIDE_INT, int,
! 						 int, unsigned HOST_WIDE_INT *,
! 						 int *, int *);
  static unsigned HOST_WIDE_INT invert_mod2n (unsigned HOST_WIDE_INT, int);
  static rtx extract_high_half (enum machine_mode, rtx);
  static rtx expand_mult_highpart (enum machine_mode, rtx, rtx, rtx, int, int);
--- 2385,2391 ----
  static rtx expand_mult_const (enum machine_mode, rtx, HOST_WIDE_INT, rtx,
  			      const struct algorithm *, enum mult_variant);
  static unsigned HOST_WIDE_INT choose_multiplier (unsigned HOST_WIDE_INT, int,
! 						 int, rtx *, int *, int *);
  static unsigned HOST_WIDE_INT invert_mod2n (unsigned HOST_WIDE_INT, int);
  static rtx extract_high_half (enum machine_mode, rtx);
  static rtx expand_mult_highpart (enum machine_mode, rtx, rtx, rtx, int, int);
*************** ceil_log2 (unsigned HOST_WIDE_INT x)
*** 3112,3119 ****
  static
  unsigned HOST_WIDE_INT
  choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision,
! 		   unsigned HOST_WIDE_INT *multiplier_ptr,
! 		   int *post_shift_ptr, int *lgup_ptr)
  {
    HOST_WIDE_INT mhigh_hi, mlow_hi;
    unsigned HOST_WIDE_INT mhigh_lo, mlow_lo;
--- 3111,3117 ----
  static
  unsigned HOST_WIDE_INT
  choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision,
! 		   rtx *multiplier_ptr, int *post_shift_ptr, int *lgup_ptr)
  {
    HOST_WIDE_INT mhigh_hi, mlow_hi;
    unsigned HOST_WIDE_INT mhigh_lo, mlow_lo;
*************** choose_multiplier (unsigned HOST_WIDE_IN
*** 3185,3196 ****
    if (n < HOST_BITS_PER_WIDE_INT)
      {
        unsigned HOST_WIDE_INT mask = ((unsigned HOST_WIDE_INT) 1 << n) - 1;
!       *multiplier_ptr = mhigh_lo & mask;
        return mhigh_lo >= mask;
      }
    else
      {
!       *multiplier_ptr = mhigh_lo;
        return mhigh_hi;
      }
  }
--- 3183,3194 ----
    if (n < HOST_BITS_PER_WIDE_INT)
      {
        unsigned HOST_WIDE_INT mask = ((unsigned HOST_WIDE_INT) 1 << n) - 1;
!       *multiplier_ptr = GEN_INT (mhigh_lo & mask);
        return mhigh_lo >= mask;
      }
    else
      {
!       *multiplier_ptr = GEN_INT (mhigh_lo);
        return mhigh_hi;
      }
  }
*************** expand_divmod (int rem_flag, enum tree_c
*** 3849,3857 ****
  	  {
  	    if (unsignedp)
  	      {
! 		unsigned HOST_WIDE_INT mh, ml;
  		int pre_shift, post_shift;
  		int dummy;
  		unsigned HOST_WIDE_INT d = (INTVAL (op1)
  					    & GET_MODE_MASK (compute_mode));

--- 3847,3856 ----
  	  {
  	    if (unsignedp)
  	      {
! 		unsigned HOST_WIDE_INT mh;
  		int pre_shift, post_shift;
  		int dummy;
+ 		rtx ml;
  		unsigned HOST_WIDE_INT d = (INTVAL (op1)
  					    & GET_MODE_MASK (compute_mode));

*************** expand_divmod (int rem_flag, enum tree_c
*** 3917,3924 ****
  			      = (shift_cost[compute_mode][post_shift - 1]
  				 + shift_cost[compute_mode][1]
  				 + 2 * add_cost[compute_mode]);
! 			    t1 = gen_int_mode (ml, compute_mode);
! 			    t1 = expand_mult_highpart (compute_mode, op0, t1,
  						       NULL_RTX, 1,
  						       max_cost - extra_cost);
  			    if (t1 == 0)
--- 3916,3922 ----
  			      = (shift_cost[compute_mode][post_shift - 1]
  				 + shift_cost[compute_mode][1]
  				 + 2 * add_cost[compute_mode]);
! 			    t1 = expand_mult_highpart (compute_mode, op0, ml,
  						       NULL_RTX, 1,
  						       max_cost - extra_cost);
  			    if (t1 == 0)
*************** expand_divmod (int rem_flag, enum tree_c
*** 3953,3960 ****
  			    extra_cost
  			      = (shift_cost[compute_mode][pre_shift]
  				 + shift_cost[compute_mode][post_shift]);
! 			    t2 = gen_int_mode (ml, compute_mode);
! 			    t2 = expand_mult_highpart (compute_mode, t1, t2,
  						       NULL_RTX, 1,
  						       max_cost - extra_cost);
  			    if (t2 == 0)
--- 3951,3957 ----
  			    extra_cost
  			      = (shift_cost[compute_mode][pre_shift]
  				 + shift_cost[compute_mode][post_shift]);
! 			    t2 = expand_mult_highpart (compute_mode, t1, ml,
  						       NULL_RTX, 1,
  						       max_cost - extra_cost);
  			    if (t2 == 0)
*************** expand_divmod (int rem_flag, enum tree_c
*** 3981,3986 ****
--- 3978,3984 ----
  	      {
  		unsigned HOST_WIDE_INT ml;
  		int lgup, post_shift;
+ 		rtx mlr;
  		HOST_WIDE_INT d = INTVAL (op1);
  		unsigned HOST_WIDE_INT abs_d = d >= 0 ? d : -d;

*************** expand_divmod (int rem_flag, enum tree_c
*** 4063,4069 ****
  		else if (size <= HOST_BITS_PER_WIDE_INT)
  		  {
  		    choose_multiplier (abs_d, size, size - 1,
! 				       &ml, &post_shift, &lgup);
  		    if (ml < (unsigned HOST_WIDE_INT) 1 << (size - 1))
  		      {
  			rtx t1, t2, t3;
--- 4061,4068 ----
  		else if (size <= HOST_BITS_PER_WIDE_INT)
  		  {
  		    choose_multiplier (abs_d, size, size - 1,
! 				       &mlr, &post_shift, &lgup);
! 		    ml = (unsigned HOST_WIDE_INT) INTVAL (mlr);
  		    if (ml < (unsigned HOST_WIDE_INT) 1 << (size - 1))
  		      {
  			rtx t1, t2, t3;
*************** expand_divmod (int rem_flag, enum tree_c
*** 4075,4082 ****
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + add_cost[compute_mode]);
! 			t1 = gen_int_mode (ml, compute_mode);
! 			t1 = expand_mult_highpart (compute_mode, op0, t1,
  						   NULL_RTX, 0,
  						   max_cost - extra_cost);
  			if (t1 == 0)
--- 4074,4080 ----
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + add_cost[compute_mode]);
! 			t1 = expand_mult_highpart (compute_mode, op0, mlr,
  						   NULL_RTX, 0,
  						   max_cost - extra_cost);
  			if (t1 == 0)
*************** expand_divmod (int rem_flag, enum tree_c
*** 4109,4119 ****
  			  goto fail1;

  			ml |= (~(unsigned HOST_WIDE_INT) 0) << (size - 1);
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + 2 * add_cost[compute_mode]);
! 			t1 = gen_int_mode (ml, compute_mode);
! 			t1 = expand_mult_highpart (compute_mode, op0, t1,
  						   NULL_RTX, 0,
  						   max_cost - extra_cost);
  			if (t1 == 0)
--- 4107,4117 ----
  			  goto fail1;

  			ml |= (~(unsigned HOST_WIDE_INT) 0) << (size - 1);
+ 			mlr = gen_int_mode (ml, compute_mode);
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + 2 * add_cost[compute_mode]);
! 			t1 = expand_mult_highpart (compute_mode, op0, mlr,
  						   NULL_RTX, 0,
  						   max_cost - extra_cost);
  			if (t1 == 0)
*************** expand_divmod (int rem_flag, enum tree_c
*** 4163,4171 ****
        /* We will come here only for signed operations.  */
  	if (op1_is_constant && HOST_BITS_PER_WIDE_INT >= size)
  	  {
! 	    unsigned HOST_WIDE_INT mh, ml;
  	    int pre_shift, lgup, post_shift;
  	    HOST_WIDE_INT d = INTVAL (op1);

  	    if (d > 0)
  	      {
--- 4161,4170 ----
        /* We will come here only for signed operations.  */
  	if (op1_is_constant && HOST_BITS_PER_WIDE_INT >= size)
  	  {
! 	    unsigned HOST_WIDE_INT mh;
  	    int pre_shift, lgup, post_shift;
  	    HOST_WIDE_INT d = INTVAL (op1);
+ 	    rtx ml;

  	    if (d > 0)
  	      {
*************** expand_divmod (int rem_flag, enum tree_c
*** 4207,4214 ****
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + 2 * add_cost[compute_mode]);
! 			t3 = gen_int_mode (ml, compute_mode);
! 			t3 = expand_mult_highpart (compute_mode, t2, t3,
  						   NULL_RTX, 1,
  						   max_cost - extra_cost);
  			if (t3 != 0)
--- 4206,4212 ----
  			extra_cost = (shift_cost[compute_mode][post_shift]
  				      + shift_cost[compute_mode][size - 1]
  				      + 2 * add_cost[compute_mode]);
! 			t3 = expand_mult_highpart (compute_mode, t2, ml,
  						   NULL_RTX, 1,
  						   max_cost - extra_cost);
  			if (t3 != 0)


Roger
--


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