This is the followup based on the review at https://inbox.sourceware.org/gcc-patches/cafiyyc3xeg75dswaf63zbu5uelpeaeohwgfogavydwouuj7...@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_apin...@quicinc.com> --- gcc/fold-const.cc | 6 +++--- gcc/match.pd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 35fcf5087fb..5f48ced5063 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -7246,10 +7246,10 @@ tree_swap_operands_p (const_tree arg0, const_tree arg1) 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 diff --git a/gcc/match.pd b/gcc/match.pd index 96136404f5e..79485f9678a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2845,7 +2845,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (&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)))) @@ -7658,8 +7658,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (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; -- 2.43.0