From: Alexander Monakov Date: Tue, 25 Jul 2017 14:33:39 +0000 (+0300) Subject: match.pd: reassociate multiplications X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b771c60914096866b6e8c2fa9b953b471e22708c;p=gcc.git match.pd: reassociate multiplications * match.pd ((X * CST) * Y): Reassociate to (X * Y) * CST. testsuite/ * gcc.dg/tree-ssa/assoc-2.c: New testcase. From-SVN: r250523 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 242d89dfd4f..654227cd55d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,4 +1,8 @@ -2017-07-07 Torsten Duwe +2017-07-25 Alexander Monakov + + * match.pd ((X * CST) * Y): Reassociate to (X * Y) * CST. + +2017-07-25 Torsten Duwe * common.opt: Introduce -fpatchable-function-entry command line option, and its variables function_entry_patch_area_size diff --git a/gcc/match.pd b/gcc/match.pd index 7f5807ce2f1..39e1e5c8384 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2213,6 +2213,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (mult @0 integer_minus_onep) (negate @0)) +/* Reassociate (X * CST) * Y to (X * Y) * CST. This does not introduce + signed overflow for CST != 0 && CST != -1. */ +(simplify + (mult:c (mult:s @0 INTEGER_CST@1) @2) + (if (TREE_CODE (@2) != INTEGER_CST + && !integer_zerop (@1) && !integer_minus_onep (@1)) + (mult (mult @0 @2) @1))) + /* True if we can easily extract the real and imaginary parts of a complex number. */ (match compositional_complex diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d8515ed3ed4..a5c00b4e25b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,8 @@ -2017-07-07 Torsten Duwe +2017-07-25 Alexander Monakov + + * gcc.dg/tree-ssa/assoc-2.c: New testcase. + +2017-07-25 Torsten Duwe * c-c++-common/patchable_function_entry-default.c: New test. * c-c++-common/patchable_function_entry-decl.c: Likewise. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c b/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c new file mode 100644 index 00000000000..a92c88226e5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-gimple-raw -fdump-tree-optimized-raw" } */ + +int f0(int a, int b){ + return a * 33 * b * 55; +} + +/* { dg-final { scan-tree-dump-times "mult_expr" 2 "gimple" } } */