From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 34B25385780A; Fri, 21 Jan 2022 11:19:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34B25385780A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6789] tree-optimization/104152 - add missing check for SLP constant build X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 3e0b19f1d670aa37ac06d63d059c7277ae1188d8 X-Git-Newrev: 1ad72811242eb84dde1bb2e97d0804d6eabeac8a Message-Id: <20220121111916.34B25385780A@sourceware.org> Date: Fri, 21 Jan 2022 11:19:16 +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: Fri, 21 Jan 2022 11:19:16 -0000 https://gcc.gnu.org/g:1ad72811242eb84dde1bb2e97d0804d6eabeac8a commit r12-6789-g1ad72811242eb84dde1bb2e97d0804d6eabeac8a Author: Richard Biener Date: Fri Jan 21 09:48:33 2022 +0100 tree-optimization/104152 - add missing check for SLP constant build This adds a missing check to verify we can actually build an invariant vector from components when SLP vectorizing an associatable chain. 2022-01-21 Richard Biener PR tree-optimization/104152 * tree-vect-slp.cc (vect_build_slp_tree_2): Add missing can_duplicate_and_interleave_p check. * gcc.dg/vect/pr104152.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr104152.c | 40 ++++++++++++++++++++++++++++++++++++ gcc/tree-vect-slp.cc | 13 ++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr104152.c b/gcc/testsuite/gcc.dg/vect/pr104152.c new file mode 100644 index 00000000000..3a313c32dc3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr104152.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Ofast" } */ +/* { dg-additional-options "-march=armv8.2-a+sve" { target aarch64-*-* } } */ + +#define M_PI 3.14f +#define NK 24 +#define DIM 3 + +typedef float rvec_ [3]; + +static rvec_ v0[NK] = { + { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 0 }, { 1, -1, 0 }, + { 1, 0, 1 }, { 1, 0, -1 }, { 0, 1, 1 }, { 0, 1, -1 }, { 1, 1, 1 }, + { 1, 1, -1 }, { 1, -1, 1 }, { -1, 1, 1 }, { 2, 0, 0 }, { 0, 2, 0 }, + { 0, 0, 2 }, { 3, 0, 0 }, { 0, 3, 0 }, { 0, 0, 3 }, { 4, 0, 0 }, + { 0, 4, 0 }, { 0, 0, 4 } }; + +static inline float iprod__(const rvec_ a, const rvec_ b) +{ + return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); +} + +int badaboum(rvec_ cm_mol, float **tc) +{ + float sx; + int k, d; + rvec_ kfac[3]; + + for (k = 0; k < DIM; k++) + for (d = 0; d < DIM; d++) + kfac[k][d] = M_PI * v0[k][d] / v0[d][d]; + + for (k = 0; k < DIM; k++) + { + sx = __builtin_sinf(iprod__(kfac[k], cm_mol)); + tc[k][0] += sx * iprod__(v0[k], cm_mol); + } + + return 0; +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index c3a1681d7c6..5ffb63689f2 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -1926,8 +1926,17 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node, if (dt == vect_constant_def || dt == vect_external_def) { - /* We can always build those. Might want to sort last - or defer building. */ + /* Check whether we can build the invariant. If we can't + we never will be able to. */ + tree type = TREE_TYPE (chains[0][n].op); + if (!GET_MODE_SIZE (vinfo->vector_mode).is_constant () + && (TREE_CODE (type) == BOOLEAN_TYPE + || !can_duplicate_and_interleave_p (vinfo, group_size, + type))) + { + matches[0] = false; + goto out; + } vec ops; ops.create (group_size); for (lane = 0; lane < group_size; ++lane)