This is the followup based on the review at
https://inbox.sourceware.org/gcc-patches/CAFiYyc3xeG75dsWaF63Zbu5uELPEAEoHwGfoGaVyDWouUJ70Mg@mail.gmail.com/
.
We should put ADDR_EXPR last instead of just is_gimple_invariant_address ones.
Note a few match patterns needed to be updated for this change but we get a decent improvement
as forwprop-38.c is now able to optimize during CCP rather than taking all the way to forwprop.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* fold-const.cc (tree_swap_operands_p): Put ADDR_EXPR last
instead of just is_gimple_invariant_address ones.
* match.pd (`a ptr+ b !=\== ADDR`, `ADDR !=/== ssa_name`):
Move the ADDR to the last operand. Update comment.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
if (TREE_CONSTANT (arg0))
return true;
- /* Put invariant address in arg1. */
- if (is_gimple_invariant_address (arg1))
+ /* Put addresses in arg1. */
+ if (TREE_CODE (arg1) == ADDR_EXPR)
return false;
- if (is_gimple_invariant_address (arg0))
+ if (TREE_CODE (arg0) == ADDR_EXPR)
return true;
/* It is preferable to swap two SSA_NAME to ensure a canonical form
/* (&a + b) !=/== (&a[1] + c) -> (&a[0] - &a[1]) + b !=/== c */
(for neeq (ne eq)
(simplify
- (neeq:c ADDR_EXPR@0 (pointer_plus @2 @3))
+ (neeq:c (pointer_plus @2 @3) ADDR_EXPR@0)
(with { poly_int64 diff; tree inner_type = TREE_TYPE (@3);}
(if (ptr_difference_const (@0, @2, &diff))
(neeq { build_int_cst_type (inner_type, diff); } @3))))
(for cmp (eq ne)
(simplify
- /* SSA names are canonicalized to 2nd place. */
- (cmp addr@0 SSA_NAME@1)
+ /* ADDRs are canonicalized to 2nd place. */
+ (cmp SSA_NAME@1 addr@0)
(with
{
poly_int64 off; tree base;