This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PTR-PLUS merge into the mainline
On Thu, 5 Jul 2007, Roman Zippel wrote:
> Hi,
>
> On Thu, 5 Jul 2007, Richard Guenther wrote:
>
> > Well, that's always the nature of any canonicalization.
>
> Well, I can't say that I agree with your canonicalization, but...
>
> > of course only tested on this particular testcase. It just shows
> > that it is possible to fix this in a generic way.
>
> let's take the particular test case I care about:
>
> int foo(int *p, unsigned int i)
> {
> return p[i + 1] + p[i + 2];
> }
>
> How should this be optimized within the context of your canonicalization?
For example by making fold_plusminus_mult_expr do what its comment
suggest, "No identical multiplicands; see if we can find a common
power-of-two factor ..."
Can you try the following and see if it helps m68k?
Index: fold-const.c
===================================================================
*** fold-const.c (revision 126376)
--- fold-const.c (working copy)
*************** fold_plusminus_mult_expr (enum tree_code
*** 7122,7127 ****
--- 7122,7132 ----
arg00 = TREE_OPERAND (arg0, 0);
arg01 = TREE_OPERAND (arg0, 1);
}
+ else if (TREE_CODE (arg0) == INTEGER_CST)
+ {
+ arg00 = build_one_cst (type);
+ arg01 = arg0;
+ }
else
{
arg00 = arg0;
*************** fold_plusminus_mult_expr (enum tree_code
*** 7132,7137 ****
--- 7137,7147 ----
arg10 = TREE_OPERAND (arg1, 0);
arg11 = TREE_OPERAND (arg1, 1);
}
+ else if (TREE_CODE (arg1) == INTEGER_CST)
+ {
+ arg10 = build_one_cst (type);
+ arg11 = arg1;
+ }
else
{
arg10 = arg1;