From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94393 invoked by alias); 21 Jul 2017 15:56:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 94360 invoked by uid 89); 21 Jul 2017 15:56:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Jul 2017 15:56:23 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id B1D385FB1B for ; Fri, 21 Jul 2017 18:56:21 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 1/2] match.pd: reassociate multiplications Date: Fri, 21 Jul 2017 15:56:00 -0000 Message-Id: <20170721155550.5846-1-amonakov@ispras.ru> X-SW-Source: 2017-07/txt/msg01310.txt.bz2 Previous revision here: https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00889.html Reassociate (X * CST) * Y to (X * Y) * CST, this pushes constants in multiplication chains to outermost factors, where they can be combined. Changed in this revision: - remove !TYPE_OVERFLOW_SANITIZED and !TYPE_SATURATING checks; (in previous discussion Richard indicated that introducing false negatives in UBSAN by concealing signed overflow is not a concern, and saturating types shouldn't appear here because the constant operand should be FIXED_CST) The checks for @1 being 0 or -1 remain as they are required for correctness, but since this rule is ordered after the simpler rules that fold X * {0, -1}, those checks are always false at runtime. * match.pd ((X * CST) * Y): Reassociate to (X * Y) * CST. testsuite/ * gcc.dg/tree-ssa/assoc-2.c: New testcase. --- gcc/match.pd | 8 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c diff --git a/gcc/match.pd b/gcc/match.pd index 7f5807c..39e1e5c 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/gcc.dg/tree-ssa/assoc-2.c b/gcc/testsuite/gcc.dg/tree-ssa/assoc-2.c new file mode 100644 index 0000000..a92c882 --- /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" } } */ -- 1.8.3.1