more on fortran array indexing

Toon Moene toon@moene.indiv.nluug.nl
Sun Oct 5 03:12:00 GMT 1997


Yesterday, I wrote:

>  Note that fold-const.c knows how to get rid of divisions
>  within SAVE_EXPR's (at least in principle).
>
>  IMHO, there's nothing wrong with the division.

This, however is not entirely true.  The only way to get completely  
rid of all remnants of the FLOOR_DIV_EXPR (srl's and such) is the  
following patch (which I had already applied):

The first part makes gcc deal with FLOOR_DIV_EXPR the way it deals  
with CEIL_DIV_EXPR in expressions where there is a multiple of the  
divisor in the dividend.

The second part makes up for the fact that fold() doesn't seem to  
look "into" subexpressions of the dividend.

HTH,
Toon.

PS: Although this leads to better code, it still doesn't solve the  
real problem, namely the conversions between the index type and  
`sizetype'.

*** egcs-970929/gcc/fold-const.c.orig   Fri Oct  3 10:07:37 1997
--- egcs-970929/gcc/fold-const.c        Sat Oct  4 13:18:29 1997
*************** fold (expr)
*** 4611,4619 ****
         operation, EXACT_DIV_EXPR.

!        Note that only CEIL_DIV_EXPR is rewritten now, only because the
!        others seem to be faster in some cases.  This is probably just
!        due to more work being done to optimize others in expmed.c  
than on
!        EXACT_DIV_EXPR.  */
!       if (code == CEIL_DIV_EXPR
          && multiple_of_p (type, arg0, arg1))
        return fold (build (EXACT_DIV_EXPR, type, arg0, arg1));
--- 4611,4619 ----
         operation, EXACT_DIV_EXPR.

!        Note that only CEIL_DIV_EXPR and FLOOR_DIV_EXPR are  
rewritten now,
!          only because the others seem to be faster in some cases.
!          This is probably just due to more work being done to optimize
!          others in expmed.c than on EXACT_DIV_EXPR.  */
!       if ((code == CEIL_DIV_EXPR || code == FLOOR_DIV_EXPR)
          && multiple_of_p (type, arg0, arg1))
        return fold (build (EXACT_DIV_EXPR, type, arg0, arg1));
*************** fold (expr)
*** 4657,4660 ****
--- 4657,4680 ----
          STRIP_NOPS (xarg0);

+           if (TREE_CODE (xarg0) == MULT_EXPR
+               && multiple_of_p (type, TREE_OPERAND (xarg0, 0), arg1))
+             {
+               return fold (build (MULT_EXPR, type,
+                                   fold (build (EXACT_DIV_EXPR, type,
+                                                TREE_OPERAND (xarg0, 0),
+                                                arg1)),
+                                   TREE_OPERAND (xarg0, 1)));
+             }
+
+           if (TREE_CODE (xarg0) == MULT_EXPR
+               && multiple_of_p (Ttype, REE_OPERAND (xarg0, 1), arg1))
+             {
+               return fold (build (MULT_EXPR, type,
+                                   fold (build (EXACT_DIV_EXPR, type,
+                                                TREE_OPERAND (xarg0, 1),
+                                                arg1)),
+                                   TREE_OPERAND (xarg0, 0)));
+             }
+
          if (TREE_CODE (xarg0) == PLUS_EXPR
              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST)



More information about the Gcc mailing list