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]

expand_divmod tweek


Hi,
Sign extending operands makes us to miss the optimization in
expand_divmod
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -march=k8" } */
/* { dg-final { scan-assembler "and.*magic" } } */

/* Should be done as "andw $32767, magic".  */
unsigned short magic;
t()
{
	magic%=(unsigned short)0x8000U;
}

Wed Feb 19 11:08:36 CET 2003  Jan Hubicka  <jh at suse dot cz>
	* expmed.c (expand_divmod): Undo sign extensions for unsigned operands
Index: expmed.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expmed.c,v
retrieving revision 1.125.2.2
diff -c -3 -p -r1.125.2.2 expmed.c
*** expmed.c	14 Dec 2002 22:06:04 -0000	1.125.2.2
--- expmed.c	19 Feb 2003 10:07:58 -0000
*************** expand_divmod (rem_flag, code, mode, op0
*** 2956,2966 ****
    int op1_is_constant, op1_is_pow2;
    int max_cost, extra_cost;
    static HOST_WIDE_INT last_div_const = 0;
  
    op1_is_constant = GET_CODE (op1) == CONST_INT;
!   op1_is_pow2 = (op1_is_constant
! 		 && ((EXACT_POWER_OF_2_OR_ZERO_P (INTVAL (op1))
! 		      || (! unsignedp && EXACT_POWER_OF_2_OR_ZERO_P (-INTVAL (op1))))));
  
    /*
       This is the structure of expand_divmod:
--- 2956,2972 ----
    int op1_is_constant, op1_is_pow2;
    int max_cost, extra_cost;
    static HOST_WIDE_INT last_div_const = 0;
+   static HOST_WIDE_INT ext_op1;
  
    op1_is_constant = GET_CODE (op1) == CONST_INT;
!   if (op1_is_constant)
!     {
!       ext_op1 = INTVAL (op1);
!       if (unsignedp)
! 	ext_op1 &= GET_MODE_MASK (mode);
!       op1_is_pow2 = ((EXACT_POWER_OF_2_OR_ZERO_P (ext_op1)
! 		     || (! unsignedp && EXACT_POWER_OF_2_OR_ZERO_P (-ext_op1))));
!     }
  
    /*
       This is the structure of expand_divmod:
*************** expand_divmod (rem_flag, code, mode, op0
*** 3140,3146 ****
  		unsigned HOST_WIDE_INT mh, ml;
  		int pre_shift, post_shift;
  		int dummy;
! 		unsigned HOST_WIDE_INT d = INTVAL (op1);
  
  		if (EXACT_POWER_OF_2_OR_ZERO_P (d))
  		  {
--- 3146,3153 ----
  		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));
  
  		if (EXACT_POWER_OF_2_OR_ZERO_P (d))
  		  {


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