simplify_shift_count reversions and fixes

Richard Henderson rth@cygnus.com
Wed Aug 16 01:08:00 GMT 2000


2000-08-11  Richard Henderson  <rth@cygnus.com>

        * combine.c (simplify_shift_const): Obey SHIFT_COUNT_TRUNCATED.

This patch broke Spec95 for alphaev6; 126.gcc of all things.
Further, I wrote a patch to fix it, committed it, then as I
was writing a description of the fix, changed my mind.

The problem with the original fix is that we'll artificially
raise the shift count e.g. for ASHIFTRT when we know that there
are extra sign bit copies hanging about.  Then when we go to
combine adjacent shifts, we wind up with nonsense shift counts
like 117.  With the SHIFT_COUNT_TRUNCATED hook inside the
reduction loop, this results in incorrect code via cropping
the shift count instead of saturating it.

Anyway, I think obeying SHIFT_COUNT_TRUNCATED before the main
loop is a simpler solution than saturating the shift count at
each point inside the loop.

I reduced the test case and committed it as execute/20000815-1.c.



r~


        * combine.c (simplify_shift_const): Revert previous two
        changes.  If SHIFT_COUNT_TRUNCATED, crop the shift count
        before the main loop.

Index: combine.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/combine.c,v
retrieving revision 1.144
diff -c -p -d -r1.144 combine.c
*** combine.c	2000/08/16 06:22:20	1.144
--- combine.c	2000/08/16 07:54:31
*************** simplify_shift_const (x, code, result_mo
*** 8851,8856 ****
--- 8851,8864 ----
  
    count = input_count;
  
+   /* Make sure and truncate the "natural" shift on the way in.  We don't
+      want to do this inside the loop as it makes it more difficult to
+      combine shifts.  */
+ #ifdef SHIFT_COUNT_TRUNCATED
+   if (SHIFT_COUNT_TRUNCATED)
+     count %= GET_MODE_BITSIZE (mode);
+ #endif
+ 
    /* Unless one of the branches of the `if' in this loop does a `continue',
       we will `break' the loop after the `if'.  */
  
*************** simplify_shift_const (x, code, result_mo
*** 8879,8889 ****
  	   ? result_mode : mode);
  
        /* Handle cases where the count is greater than the size of the mode
! 	 minus 1.  If SHIFT_COUNT_TRUNCATED, there aren't really any such
! 	 cases.  Otherwise, for ASHIFT, use the size minus one as the count
! 	 (this can occur when simplifying (lshiftrt (ashiftrt ..))).  For
! 	 rotates, take the count modulo the size.  For other shifts, the
! 	 result is zero.
  
  	 Since these shifts are being produced by the compiler by combining
  	 multiple operations, each of which are defined, we know what the
--- 8887,8896 ----
  	   ? result_mode : mode);
  
        /* Handle cases where the count is greater than the size of the mode
! 	 minus 1.  For ASHIFT, use the size minus one as the count (this can
! 	 occur when simplifying (lshiftrt (ashiftrt ..))).  For rotates,
! 	 take the count modulo the size.  For other shifts, the result is
! 	 zero.
  
  	 Since these shifts are being produced by the compiler by combining
  	 multiple operations, each of which are defined, we know what the
*************** simplify_shift_const (x, code, result_mo
*** 8891,8901 ****
  
        if (count > GET_MODE_BITSIZE (shift_mode) - 1)
  	{
- #ifdef SHIFT_COUNT_TRUNCATED
- 	  if (SHIFT_COUNT_TRUNCATED)
- 	    count %= GET_MODE_BITSIZE (shift_mode);
- 	  else
- #endif
  	  if (code == ASHIFTRT)
  	    count = GET_MODE_BITSIZE (shift_mode) - 1;
  	  else if (code == ROTATE || code == ROTATERT)
--- 8898,8903 ----
*************** simplify_shift_const (x, code, result_mo
*** 9149,9156 ****
  		    break;
  
  		  count += first_count;
- 		  if (count >= GET_MODE_BITSIZE (shift_mode))
- 		    count = GET_MODE_BITSIZE (shift_mode) - 1;
  		  varop = XEXP (varop, 0);
  		  continue;
  		}
--- 9151,9156 ----
*************** simplify_shift_const (x, code, result_mo
*** 9203,9211 ****
  		code = first_code, count = -signed_count;
  	      else
  		count = signed_count;
- 
- 	      if (count >= GET_MODE_BITSIZE (shift_mode))
- 		count = GET_MODE_BITSIZE (shift_mode) - 1;
  
  	      varop = XEXP (varop, 0);
  	      continue;
--- 9203,9208 ----


More information about the Gcc-patches mailing list