From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 44C3A386186F; Mon, 19 Feb 2024 08:45:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44C3A386186F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708332309; bh=C5UEtLbmD1IHBmKHhS+Md3WLt2tQ1c1euAoZqliNdG8=; h=From:To:Subject:Date:From; b=p9XLSOusRZHS8cvDB4wDr1k/9ImD0XfPoMvYEV0aKrhjJ50RB/Uwti8/IHDf/XSSS 6JerHvW8Eja8FPqNG6sh+D4Dc+DAUvAbUeQLykAQ4ZZKMsjIHeoePGgSa0CMwvaGog uitocAbGob/2wd551WZtftkkMimB+Lqk18z74mbw= 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 r14-9061] match.pd: Fix ICE on BIT_INSERT_EXPR of BIT_FIELD_REF folding [PR113967] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 6082024891e421bfd81d8f708a7411f4019d0d97 X-Git-Newrev: 2bfdeca19d96239479488cd07b1e952d95a02f72 Message-Id: <20240219084509.44C3A386186F@sourceware.org> Date: Mon, 19 Feb 2024 08:45:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2bfdeca19d96239479488cd07b1e952d95a02f72 commit r14-9061-g2bfdeca19d96239479488cd07b1e952d95a02f72 Author: Jakub Jelinek Date: Mon Feb 19 09:42:22 2024 +0100 match.pd: Fix ICE on BIT_INSERT_EXPR of BIT_FIELD_REF folding [PR113967] The following testcase ICEs, because BIT_FIELD_REF's position is not multiple of the vector element's bit size and the code uses exact_div to divide those 2 values. For BIT_INSERT_EXPR, the tree-cfg.cc verification verifies the position is a multiple of the inserted bit size when inserting into vectors, but for BIT_FIELD_REF the position can be arbitrary if within the range. The following patch fixes that. 2024-02-19 Jakub Jelinek PR tree-optimization/113967 * match.pd (bit_insert @0 (BIT_FIELD_REF @1 ..) ..): Require in condition that @rpos is multiple of vector element size. * gcc.dg/pr113967.c: New test. Diff: --- gcc/match.pd | 4 +++- gcc/testsuite/gcc.dg/pr113967.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 711c3a10c3ff..c5b6540f939a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8586,7 +8586,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || optimize_vectors_before_lowering_p ()) && types_match (@0, @1) && types_match (TREE_TYPE (TREE_TYPE (@0)), TREE_TYPE (@2)) - && TYPE_VECTOR_SUBPARTS (type).is_constant ()) + && TYPE_VECTOR_SUBPARTS (type).is_constant () + && multiple_p (wi::to_poly_offset (@rpos), + wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (type))))) (with { unsigned HOST_WIDE_INT elsz diff --git a/gcc/testsuite/gcc.dg/pr113967.c b/gcc/testsuite/gcc.dg/pr113967.c new file mode 100644 index 000000000000..21621809564b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr113967.c @@ -0,0 +1,14 @@ +/* PR tree-optimization/113967 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef unsigned short W __attribute__((vector_size (4 * sizeof (short)))); + +void +foo (W *p) +{ + W x = *p; + W y = {}; + __builtin_memcpy (&y, 1 + (char *) &x, sizeof (short)); + *p = y; +}