From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 9AAED3857011; Wed, 14 Feb 2024 11:43:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AAED3857011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1707911010; bh=E1tm2OyjeWYPGzVsUGVPYtS2hYuNEqdzRV+YPsmS0xQ=; h=From:To:Subject:Date:From; b=k2T/GafZ4G3F49d0w7F82uXR5C1jv7jEszACE8Nggw1KWwZ2a0bWnhikVLTifvsiD wOwHaJxRgsDEFrenx6M8N5pKwyi7AS+GQp9IoQdHFQ88FVDGRplMPsqXyyNI7E3tGj NYLYp96bAl1EFi67gUqxQejzvoAFUyopfl02FYQU= 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-10155] tree-optimization/113896 - reduction of permuted external vector X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: e018abbc43e69a7f6e118409a852111f7ba53098 X-Git-Newrev: 2f16c53558d01135f0f78cf78a2f722b774684d7 Message-Id: <20240214114330.9AAED3857011@sourceware.org> Date: Wed, 14 Feb 2024 11:43:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2f16c53558d01135f0f78cf78a2f722b774684d7 commit r12-10155-g2f16c53558d01135f0f78cf78a2f722b774684d7 Author: Richard Biener Date: Tue Feb 13 13:43:44 2024 +0100 tree-optimization/113896 - reduction of permuted external vector The following fixes eliding of the permutation of a BB reduction of an existing vector which breaks materialization of live lanes as we fail to permute the SLP_TREE_SCALAR_STMTS vector. PR tree-optimization/113896 * tree-vect-slp.cc (vect_optimize_slp): Permute SLP_TREE_SCALAR_STMTS when eliding a permuation in a VEC_PERM node we need to preserve because it wraps an extern vector. * g++.dg/torture/pr113896.C: New testcase. Diff: --- gcc/testsuite/g++.dg/torture/pr113896.C | 35 +++++++++++++++++++++++++++++++++ gcc/tree-vect-slp.cc | 9 +++++++++ 2 files changed, 44 insertions(+) diff --git a/gcc/testsuite/g++.dg/torture/pr113896.C b/gcc/testsuite/g++.dg/torture/pr113896.C new file mode 100644 index 000000000000..534c1c2e1cce --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr113896.C @@ -0,0 +1,35 @@ +// { dg-do run } +// { dg-additional-options "-ffast-math" } + +double a1 = 1.0; +double a2 = 1.0; + +void __attribute__((noipa)) +f(double K[2], bool b) +{ + double A[] = { + b ? a1 : a2, + 0, + 0, + 0 + }; + + double sum{}; + for(double a : A) sum += a; + for(double& a : A) a /= sum; + + if (b) { + K[0] = A[0]; // 1.0 + K[1] = A[1]; // 0.0 + } else { + K[0] = A[0] + A[1]; + } +} + +int main() +{ + double K[2]{}; + f(K, true); + if (K[0] != 1. || K[1] != 0.) + __builtin_abort (); +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index af477c31aa3d..b3e3d9e70094 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4058,6 +4058,15 @@ vect_optimize_slp (vec_info *vinfo) { /* Preserve the special VEC_PERM we use to shield existing vector defs from the rest. But make it a no-op. */ + auto_vec saved; + saved.create (SLP_TREE_SCALAR_STMTS (old).length ()); + for (unsigned i = 0; + i < SLP_TREE_SCALAR_STMTS (old).length (); ++i) + saved.quick_push (SLP_TREE_SCALAR_STMTS (old)[i]); + for (unsigned i = 0; + i < SLP_TREE_SCALAR_STMTS (old).length (); ++i) + SLP_TREE_SCALAR_STMTS (old)[i] + = saved[SLP_TREE_LANE_PERMUTATION (old)[i].second]; unsigned i = 0; for (std::pair &p : SLP_TREE_LANE_PERMUTATION (old))