From: Marc Glisse Date: Tue, 27 Jun 2017 09:42:38 +0000 (+0200) Subject: Simple reassoc transforms in match.pd X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1e7df2e63a369ffcc658dd5e1e3d57dabaa017c2;p=gcc.git Simple reassoc transforms in match.pd 2017-06-27 Marc Glisse gcc/ * match.pd ((A+-B)+(C-A), (A+B)-(A-C)): New transformations. gcc/testsuite/ * gcc.dg/tree-ssa/assoc-1.c: New file. From-SVN: r249686 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3fd4629607a..665e0b5b085 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2017-06-27 Marc Glisse + + * match.pd ((A+-B)+(C-A), (A+B)-(A-C)): New transformations. + 2017-06-27 Marc Glisse * builtin-types.def (BT_FENV_T_PTR, BT_CONST_FENV_T_PTR, diff --git a/gcc/match.pd b/gcc/match.pd index a4cae113bc8..083a5742bc3 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1321,6 +1321,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (minus @0 (minus @0 @1)) @1) + /* (A +- B) + (C - A) -> C +- B */ + /* (A + B) - (A - C) -> B + C */ + /* More cases are handled with comparisons. */ + (simplify + (plus:c (plus:c @0 @1) (minus @2 @0)) + (plus @2 @1)) + (simplify + (plus:c (minus @0 @1) (minus @2 @0)) + (minus @2 @1)) + (simplify + (minus (plus:c @0 @1) (minus @0 @2)) + (plus @1 @2)) /* (A +- CST1) +- CST2 -> A + CST3 Use view_convert because it is safe for vectors and equivalent for diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 901d4a53d85..7364606164c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-27 Marc Glisse + + * gcc.dg/tree-ssa/assoc-1.c: New file. + 2017-06-27 Paolo Carlini PR c++/62046 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assoc-1.c b/gcc/testsuite/gcc.dg/tree-ssa/assoc-1.c new file mode 100644 index 00000000000..f9821910bd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/assoc-1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw -fno-tree-reassoc" } */ + +int f0(int a,int b,int c){ + int d = a + b; + int e = c + b; + return d - e; +} +int f1(int a,int b,int c){ + int d = a + b; + int e = b - c; + return d - e; +} +int f2(int a,int b,int c){ + int d = a + b; + int e = c - b; + return e + d; +} +int f3(int a,int b,int c){ + int d = a - b; + int e = c - b; + return d - e; +} +int f4(int a,int b,int c){ + int d = b - a; + int e = c - b; + return e + d; +} + +/* { dg-final { scan-tree-dump-times "plus_expr" 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "minus_expr" 3 "optimized" } } */