From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 5A12B3857C77; Sat, 13 Mar 2021 08:00:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A12B3857C77 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-7656] match.pd: Don't optimize vector X + (X << C) -> X * (1 + (1 << C)) if there is no mult support [PR99 X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 3972574f11e5d49f12ad88faf2346f77ffc6e523 X-Git-Newrev: bbdf59fdbc2ce41ccfac807b15cf3fac7b465a56 Message-Id: <20210313080045.5A12B3857C77@sourceware.org> Date: Sat, 13 Mar 2021 08:00:45 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Mar 2021 08:00:45 -0000 https://gcc.gnu.org/g:bbdf59fdbc2ce41ccfac807b15cf3fac7b465a56 commit r11-7656-gbbdf59fdbc2ce41ccfac807b15cf3fac7b465a56 Author: Jakub Jelinek Date: Sat Mar 13 08:56:15 2021 +0100 match.pd: Don't optimize vector X + (X << C) -> X * (1 + (1 << C)) if there is no mult support [PR99544] E.g. on aarch64, the target has V2DImode addition and shift by scalar optabs, but doesn't have V2DImode multiply. The following testcase ICEs because this simplification is done after last lowering, but generally, even if it is done before that, turning it into a multiplication will not be an improvement because that means scalarization, while the former can be done in vectors. It would be nice if we added expansion support for vector multiplication by uniform constants using shifts and additions like we have for scalar multiplication, but that is something that can be done in stage1. 2021-03-13 Jakub Jelinek PR tree-optimization/99544 * match.pd (X + (X << C) -> X * (1 + (1 << C))): Don't simplify if for vector types multiplication can't be done in type's mode. * gcc.dg/gomp/pr99544.c: New test. Diff: --- gcc/match.pd | 10 ++++++++-- gcc/testsuite/gcc.dg/gomp/pr99544.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index a34c283e28c..036f92fa959 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2788,7 +2788,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (plus:c @0 (lshift:s @0 INTEGER_CST@1)) (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) && tree_fits_uhwi_p (@1) - && tree_to_uhwi (@1) < element_precision (type)) + && tree_to_uhwi (@1) < element_precision (type) + && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + || optab_handler (smul_optab, + TYPE_MODE (type)) != CODE_FOR_nothing)) (with { tree t = type; if (!TYPE_OVERFLOW_WRAPS (t)) t = unsigned_type_for (t); wide_int w = wi::set_bit_in_zero (tree_to_uhwi (@1), @@ -2804,7 +2807,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && tree_fits_uhwi_p (@1) && tree_to_uhwi (@1) < element_precision (type) && tree_fits_uhwi_p (@2) - && tree_to_uhwi (@2) < element_precision (type)) + && tree_to_uhwi (@2) < element_precision (type) + && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + || optab_handler (smul_optab, + TYPE_MODE (type)) != CODE_FOR_nothing)) (with { tree t = type; if (!TYPE_OVERFLOW_WRAPS (t)) t = unsigned_type_for (t); unsigned int prec = element_precision (type); diff --git a/gcc/testsuite/gcc.dg/gomp/pr99544.c b/gcc/testsuite/gcc.dg/gomp/pr99544.c new file mode 100644 index 00000000000..4ea07cf2b4d --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/pr99544.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/99544 */ +/* { dg-do compile } */ +/* { dg-options "-Os -fopenmp" } */ + +long +foo (long a, long b, long c) +{ + long d, e; + #pragma omp teams distribute parallel for simd firstprivate (a, b, c) lastprivate(e) + for (d = a; d < b; d++) + e = c + d * 5; + return e; +}