The following makes reassoc also break up subtracts for values used
on the positive side of a MINUS_EXPR.

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

Richard.

2017-08-03  Richard Biener  <rguent...@suse.de>

        * tree-ssa-reassoc.c (should_break_up_subtract): Also break
        up if the use is in USE - X.

        * gcc.dg/tree-ssa/reassoc-23.c: Adjust to fool early folding
        and CSE.

Index: gcc/tree-ssa-reassoc.c
===================================================================
--- gcc/tree-ssa-reassoc.c      (revision 250818)
+++ gcc/tree-ssa-reassoc.c      (working copy)
@@ -4718,7 +4718,9 @@ should_break_up_subtract (gimple *stmt)
       && (immusestmt = get_single_immediate_use (lhs))
       && is_gimple_assign (immusestmt)
       && (gimple_assign_rhs_code (immusestmt) == PLUS_EXPR
-         ||  gimple_assign_rhs_code (immusestmt) == MULT_EXPR))
+         || (gimple_assign_rhs_code (immusestmt) == MINUS_EXPR
+             && gimple_assign_rhs1 (immusestmt) == lhs)
+         || gimple_assign_rhs_code (immusestmt) == MULT_EXPR))
     return true;
   return false;
 }
Index: gcc/testsuite/gcc.dg/tree-ssa/reassoc-23.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/reassoc-23.c  (revision 250818)
+++ gcc/testsuite/gcc.dg/tree-ssa/reassoc-23.c  (working copy)
@@ -6,9 +6,10 @@ foo(unsigned int a, unsigned int b, unsi
     unsigned int e, unsigned int f, unsigned int g, unsigned int h)
 {
   /* Should be transformed into e = 20 */
-  unsigned int i = (a + 9) + (c + 8);
-  unsigned int j = (-c + 1) + (-a + 2);
-
+  unsigned int i = (a + 9);
+  unsigned int j = (-c + 1);
+  i += (c + 8);
+  j += (-a + 2);
   e = i + j;
   return e;
 }

Reply via email to