This is the mail archive of the gcc@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]

shift subreg patch [was: gcc/Alpha]


The attached patch cleans up this untidiness.


r~


On Fri, Dec 12, 1997 at 10:31:26AM +0100, Robert Harley wrote:
> >Can you give an example of what you mean?
> 
> OK.  A 'zapnot' appears for code like this:
> 
> ------------------------------------------------------------------------------
> typedef unsigned long u64;
> 
> #define TAB_SIZE (16UL)
> #define TAB_MASK (TAB_SIZE-1UL)
> 
> u64 foo(u64 bh, u64 bl, u64 *p)
> {
>   u64 sh;
>   static const int tab[TAB_SIZE] = { 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0 };
> 
>   do {
>     sh = (u64)tab[bl & TAB_MASK];
>     bl >>= sh; bh >>= sh;
>   } while (!(bl & 1UL));
> 
>   *p = bh;
>   return bl;
> } /* end foo */
> ------------------------------------------------------------------------------
> 
> But then it disappears mysteriously at the slightest change!
> For instance, if the second shift is commented out.
> 
> -- Rob.
Sun Dec 14 18:56:10 1997  Richard Henderson  <rth@cygnus.com>

	* expmed.c (expand_shift): If SHIFT_COUNT_TRUNCATED, drop a SUBREG.


Index: expmed.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/gcc/expmed.c,v
retrieving revision 1.6
diff -u -p -d -r1.6 expmed.c
--- expmed.c	1997/12/07 00:28:26	1.6
+++ expmed.c	1997/12/15 02:54:10
@@ -1752,11 +1752,16 @@ expand_shift (code, mode, shifted, amoun
   op1 = expand_expr (amount, NULL_RTX, VOIDmode, 0);
 
 #ifdef SHIFT_COUNT_TRUNCATED
-  if (SHIFT_COUNT_TRUNCATED
-      && GET_CODE (op1) == CONST_INT
-      && (unsigned HOST_WIDE_INT) INTVAL (op1) >= GET_MODE_BITSIZE (mode))
-    op1 = GEN_INT ((unsigned HOST_WIDE_INT) INTVAL (op1)
-		   % GET_MODE_BITSIZE (mode));
+  if (SHIFT_COUNT_TRUNCATED)
+    {
+      if (GET_CODE (op1) == CONST_INT
+          && (unsigned HOST_WIDE_INT) INTVAL (op1) >= GET_MODE_BITSIZE (mode))
+        op1 = GEN_INT ((unsigned HOST_WIDE_INT) INTVAL (op1)
+		       % GET_MODE_BITSIZE (mode));
+      else if (GET_CODE (op1) == SUBREG
+	       && SUBREG_WORD (op1) == 0)
+	op1 = SUBREG_REG (op1);
+    }
 #endif
 
   if (op1 == const0_rtx)

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