This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [PATCH] Fix canonicalization of addresses


> So after the patch we would canonicalize the above to base + (ind - 1) * 2?

Yes, that's still suboptimal for most targets but simply disabling the 
factorization doesn't seem to be doable at this point.

> To even catch the case where the user writes (1-ind)*-2 can you instead
> extend fold_binary at
>
>     case MULT_EXPR:
>       /* (-A) * (-B) -> A * B  */
>       if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
>         return fold_build2 (MULT_EXPR, type,
>                             fold_convert (type, TREE_OPERAND (arg0, 0)),
>                             fold_convert (type, negate_expr (arg1)));
>       if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
>         return fold_build2 (MULT_EXPR, type,
>                             fold_convert (type, negate_expr (arg0)),
>                             fold_convert (type, TREE_OPERAND (arg1, 0)));
>
> to also handle negative constants instead of just NEGATE_EXPR?
>
> IMHO this would be the better approach.

What would be better than what exactly?

> I consider the expr.c hunk a hack - what fixes this up at -O2 vs. -Os?

We have a testcase for which it hugely helps at -O2 because you can CSE a 
bunch of (base + ind*2) calculations, leaving only the displacements as 
adjustments.  When the displacements are inside the *2, CSE is not as 
effective and addresses are needlessly recomputed.

> Can we enable that at -Os as well instead? 

IMO the transformations should be done at any optimization level, they just 
get us back to where we were before.

-- 
Eric Botcazou


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