From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B5168385773F; Sat, 22 Apr 2023 08:33:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5168385773F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682152404; bh=eZhFN9lqIE3rRLQFTJzv6s2bYH5Xi76rvri7DitDAPU=; h=From:To:Subject:Date:From; b=IRE+uHFl4UwXOnWHHX7HYQkx/p1JsN4SXh2y0f/ehiH8zKfgK8lneVzJeEczP20RL TrpjXi94OblpthJ90NkaXEF0ejdFGPTcLs0IY18Zn+c7AhjuVM5PbXw7ZLDEI97Qkx bTgjaz4V+VBZHJHJyi4FVE0HFE0V2ASxypDC3SCo= 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 r13-7234] match.pd: Fix fneg/fadd optimization [PR109583] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 19c8d725e68c22c6dad156e40244f263ac19d55f X-Git-Newrev: 9b6bf076c11cba0f9ccdace63e8b4044b1a858ea Message-Id: <20230422083324.B5168385773F@sourceware.org> Date: Sat, 22 Apr 2023 08:33:24 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9b6bf076c11cba0f9ccdace63e8b4044b1a858ea commit r13-7234-g9b6bf076c11cba0f9ccdace63e8b4044b1a858ea Author: Jakub Jelinek Date: Sat Apr 22 10:24:29 2023 +0200 match.pd: Fix fneg/fadd optimization [PR109583] The following testcase ICEs on x86, foo function since my r14-22 improvement, but bar already since r13-4122. The problem is the same, in the if expression related_vector_mode is called and that starts with gcc_assert (VECTOR_MODE_P (vector_mode)); but nothing in the fneg/fadd match.pd pattern actually checks if the VEC_PERM type has VECTOR_MODE_P (vec_mode). In this case it has BLKmode and so it ICEs. The following patch makes sure we don't ICE on it. 2023-04-22 Jakub Jelinek PR tree-optimization/109583 * match.pd (fneg/fadd simplify): Don't call related_vector_mode if vec_mode is not VECTOR_MODE_P. * gcc.dg/pr109583.c: New test. (cherry picked from commit c58c0771b7a3dbd2a00cd4b6ca2301d74b6cd4e2) Diff: --- gcc/match.pd | 3 ++- gcc/testsuite/gcc.dg/pr109583.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index c5d2c36e117..1410ecdf73d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8095,7 +8095,8 @@ and, poly_uint64 wide_nunits; scalar_mode inner_mode = GET_MODE_INNER (vec_mode); } - (if (sel.series_p (0, 2, 0, 2) + (if (VECTOR_MODE_P (vec_mode) + && sel.series_p (0, 2, 0, 2) && sel.series_p (1, 2, nelts + 1, 2) && GET_MODE_2XWIDER_MODE (inner_mode).exists (&wide_elt_mode) && multiple_p (GET_MODE_NUNITS (vec_mode), 2, &wide_nunits) diff --git a/gcc/testsuite/gcc.dg/pr109583.c b/gcc/testsuite/gcc.dg/pr109583.c new file mode 100644 index 00000000000..e3fea3d510c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109583.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/109583 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -Wno-psabi" } */ +/* { dg-additional-options "-mno-avx" { target i?86-*-* x86_64-*-* } } */ + +typedef float v8sf __attribute__((vector_size (8 * sizeof (float)))); +typedef int v8si __attribute__((vector_size (8 * sizeof (int)))); + +#if __SIZEOF_INT__ == __SIZEOF_FLOAT__ +v8sf +foo (v8sf x, v8sf y) +{ + v8sf a = x - y; + v8sf b = x + y; + return __builtin_shuffle (a, b, (v8si) { 0, 9, 2, 11, 4, 13, 6, 15 }); +} + +v8sf +bar (v8sf x, v8sf y) +{ + v8sf a = x + y; + v8sf b = x - y; + return __builtin_shuffle (a, b, (v8si) { 0, 9, 2, 11, 4, 13, 6, 15 }); +} +#endif