From mboxrd@z Thu Jan 1 00:00:00 1970 From: Toon Moene To: Richard Henderson Cc: egcs@cygnus.com Subject: Re: more on fortran array indexing Date: Sun, 05 Oct 1997 03:12:00 -0000 Message-id: <9710051010.AA02184@moene.indiv.nluug.nl> References: <19971002130319.01737@dot.cygnus.com> <9710030816.AA26550@moene.indiv.nluug.nl> <19971003110425.58522@dot.cygnus.com> <9710041510.AA01646@moene.indiv.nluug.nl> X-SW-Source: 1997-10/msg00197.html 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)