This allows (p + 1) + 2 to be combined to p + 3 (also a good sign
on why that single_use stuff is "bad" - bad in case we have restricted
simplifications to a single stmt as result anyway).

This shows up in gcc.dg/20020415-1.c (and more places)

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2015-06-25  Richard Biener  <rguent...@suse.de>

        * match.pd: Allow (p +p off1) +p off2 to (p +p (off1 + off2))
        irrespective on whether the inner operation has a single use
        of both off are constant.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd        (revision 224893)
+++ gcc/match.pd        (working copy)
@@ -503,7 +520,8 @@ (define_operator_list swapped_tcc_compar
 /* Associate (p +p off1) +p off2 as (p +p (off1 + off2)).  */
 (simplify
   (pointer_plus (pointer_plus@2 @0 @1) @3)
-  (if (single_use (@2))
+  (if (single_use (@2)
+       || (TREE_CODE (@1) == INTEGER_CST && TREE_CODE (@3) == INTEGER_CST))
    (pointer_plus @0 (plus @1 @3))))
 
 /* Pattern match

Reply via email to