]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree: Canonical order for ADDR
authorAndrew Pinski <quic_apinski@quicinc.com>
Wed, 14 May 2025 16:01:07 +0000 (09:01 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Thu, 15 May 2025 06:18:26 +0000 (23:18 -0700)
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>
gcc/fold-const.cc
gcc/match.pd

index 35fcf5087fb5e984bc863ad8e84b277fa3ffb540..5f48ced50636e760514988ba0c362f27bebd3eee 100644 (file)
@@ -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
index 96136404f5e4048d8d0145abcb95eb6b89cc08b9..79485f9678a09732717cccb626de1eb283b40787 100644 (file)
@@ -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;