Patch: improve doloop detection

Dale Johannesen dalej@apple.com
Thu Sep 11 21:49:00 GMT 2003


This allows loops controlled by (unsigned int--  >  0)
to be detected as doloops.  Bootstrapped and tested on
Darwin to the extent currently possible (no diffs before & after).

2003-09-11   Dale Johannesen  <dalej@apple.com>

         * fold-const.c (fold):  Move detection of unsigned>0, <=0 a bit 
earlier.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.301
diff -u -d -b -w -c -3 -p -r1.301 fold-const.c
*** fold-const.c        8 Sep 2003 18:57:32 -0000       1.301
--- fold-const.c        11 Sep 2003 19:48:20 -0000
*************** fold (tree expr)
*** 6849,6854 ****
--- 6849,6872 ----
           TREE_SET_CODE (t, code);
         }

+       /* Treat unsigned >0 as !=0, and unsigned <=0 as ==0, just a 
little
+        earlier than was done previously.  This allows the foo++ == 
CONST
+        optimization to work in this case, which is better for some 
loops.  */
+       if (integer_zerop (arg1) && INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+         && TREE_UNSIGNED (TREE_TYPE (arg0)))
+       {
+         if (code == GT_EXPR)
+           {
+             code = NE_EXPR;
+             TREE_SET_CODE (t, code);
+           }
+         else if (code==LE_EXPR)
+           {
+             code = EQ_EXPR;
+             TREE_SET_CODE (t, code);
+           }
+       }
+
         if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
         {
           tree targ0 = strip_float_extensions (arg0);

/* { dg-do compile { target powerpc-*-darwin* } } */
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler "bdnz" } } */
#include <string.h>

void *clone (void *dest, int pattern, unsigned int count) {
   void *original_dest = dest;
   while (count-- > 0)
     *(unsigned char *) dest++ = (unsigned char) pattern;
   return original_dest;
}



More information about the Gcc-patches mailing list