From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 446663856DFC; Tue, 2 May 2023 20:14:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 446663856DFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058474; bh=ZaHnVvyvjZgXdHgN9rURROPtSHnZPqcW0dwnQhU66fw=; h=From:To:Subject:Date:From; b=hdWO+qR1YxwbUPijeQ54BeMyQtMTZdzIINecFxf9DSjtjAKgLtKHyIxne00zl78cI FoNWOCD3tJUXlfcnq1AzBjLOpJQjiwTFHlyibVzrWR64nDmxeysp6VflLhMwG8F4CC Q+KhafpenLaWgvDgJoKqdG3vX2yxZ40A8z1tqqFc= 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-10710] match.pd: When simplifying BFR of an insert, require a mode precision integral type [PR108688] X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: eadc8fd8d7fd509b001fcdbe160e2d6862c745a4 X-Git-Newrev: d87adfe1a6455025eb3ae787a6da245a62cdb446 Message-Id: <20230502201434.446663856DFC@sourceware.org> Date: Tue, 2 May 2023 20:14:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d87adfe1a6455025eb3ae787a6da245a62cdb446 commit r11-10710-gd87adfe1a6455025eb3ae787a6da245a62cdb446 Author: Andrew Pinski Date: Thu Feb 9 16:03:54 2023 +0100 match.pd: When simplifying BFR of an insert, require a mode precision integral type [PR108688] The same problem as PR 88739 has crept in but this time in match.pd when simplifying bit_field_ref of an bit_insert. That is we are generating a BIT_FIELD_REF of a non-mode-precision integral type. PR tree-optimization/108688 * match.pd (bit_field_ref [bit_insert]): Avoid generating BIT_FIELD_REFs of non-mode-precision integral operands. * gcc.c-torture/compile/pr108688-1.c: New test. (cherry picked from commit 44f308e59bfa0f93ae05b17e257d8563c12399fd) Diff: --- gcc/match.pd | 4 +++- gcc/testsuite/gcc.c-torture/compile/pr108688-1.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 8126f90ee75..91a3762e320 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6264,7 +6264,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) isize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (@1))); } (switch - (if (wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) + (if ((!INTEGRAL_TYPE_P (TREE_TYPE (@1)) + || type_has_mode_precision_p (TREE_TYPE (@1))) + && wi::leu_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) && wi::leu_p (wi::to_wide (@rpos) + wi::to_wide (@rsize), wi::to_wide (@ipos) + isize)) (BIT_FIELD_REF @1 @rsize { wide_int_to_tree (bitsizetype, diff --git a/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c b/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c new file mode 100644 index 00000000000..43d782d62bd --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c @@ -0,0 +1,15 @@ + + +union U { signed int d : 7; signed int e : 2; } u; +int a, b; + +void +foo (void) +{ + for (int i = 0; i < 64; i++) + { + u.d = a; + u.e ^= b; + } +} +