From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B57A93858C5F; Thu, 9 Feb 2023 15:11:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B57A93858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675955501; bh=ksmS6sfIXP0p9Mqr7e49bY48B9qLNf2BPiLBE0l486I=; h=From:To:Subject:Date:From; b=gSae8wXjO9UoriPkjDW04mwrIMXMkOJON95HLI7SXWQLVQ7dko7wRYRaqNFdFJUnx sQeSjJIbff97x5MoGJr3nkR37QbVE+1dn+5fBfkogOBJq4X3FkDEBuklFsgvzzCxWa Me/+fKwSbVkCpwTGQIJIqQBPqisjfX9+i8Mi+8KI= 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-5758] match.pd: Simplify BFR of insert when extracting exactly all inserted bits [PR108688] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 44f308e59bfa0f93ae05b17e257d8563c12399fd X-Git-Newrev: bcca64d70ce91e29717fb70cff252639df6902be Message-Id: <20230209151141.B57A93858C5F@sourceware.org> Date: Thu, 9 Feb 2023 15:11:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bcca64d70ce91e29717fb70cff252639df6902be commit r13-5758-gbcca64d70ce91e29717fb70cff252639df6902be Author: Jakub Jelinek Date: Thu Feb 9 16:07:40 2023 +0100 match.pd: Simplify BFR of insert when extracting exactly all inserted bits [PR108688] On Thu, Feb 09, 2023 at 09:16:17AM +0100, Richard Biener via Gcc-patches wrote: > Hmm. Can we handle the case of the extraction exactly covering the > insertion separately then and simplify to plain @1? I was suggesting that in the PR. Here it is as an incremental patch on top of Andrew's patch. On the newly added testcase the ifcvt-folding difference without/with the incremental patch is: --- pr108688.c.171t.ifcvt_ 2023-02-09 10:47:30.169916845 +0100 +++ pr108688.c.171t.ifcvt 2023-02-09 10:48:44.942793453 +0100 @@ -25,6 +25,8 @@ Number of blocks in CFG: 11 Number of blocks to update: 5 ( 45%) +Applying pattern match.pd:7487, gimple-match.cc:243200 +Applying pattern match.pd:3987, gimple-match.cc:75423 Matching expression match.pd:1677, gimple-match.cc:209 Applying pattern match.pd:1733, gimple-match.cc:109481 Matching expression match.pd:2393, gimple-match.cc:852 @@ -70,7 +72,6 @@ void foo () signed char _29; _30; unsigned int ivtmp_33; - _ifc__35; unsigned char _ifc__37; unsigned char _ifc__38; unsigned char _ifc__39; @@ -91,8 +92,7 @@ void foo () _2 = () a.0_1; _ifc__38 = u.D.2741; _ifc__39 = BIT_INSERT_EXPR <_ifc__38, _2, 0 (7 bits)>; - _ifc__35 = BIT_FIELD_REF <_ifc__39, 7, 0>; - _4 = (signed char) _ifc__35; + _4 = (signed char) _2; b.1_5 = b; _6 = (signed char) b.1_5; _7 = _4 ^ _6; 2023-02-09 Jakub Jelinek PR tree-optimization/108688 * match.pd (bit_field_ref [bit_insert]): Simplify BIT_FIELD_REF of BIT_INSERT_EXPR extracting exactly all inserted bits even when without mode precision. Formatting fixes. * gcc.c-torture/compile/pr108688-1.c: Add PR number as comment. * gcc.dg/pr108688.c: New test. Diff: --- gcc/match.pd | 9 ++++++--- gcc/testsuite/gcc.c-torture/compile/pr108688-1.c | 3 +-- gcc/testsuite/gcc.dg/pr108688.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 73e5053d155..821630d1d49 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7475,13 +7475,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (switch (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)) + || 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, - wi::to_wide (@rpos) + wi::to_wide (@rpos) - wi::to_wide (@ipos)); })) + (if (wi::eq_p (wi::to_wide (@ipos), wi::to_wide (@rpos)) + && compare_tree_int (@rsize, isize) == 0) + (convert @1)) (if (wi::geu_p (wi::to_wide (@ipos), wi::to_wide (@rpos) + wi::to_wide (@rsize)) || wi::geu_p (wi::to_wide (@rpos), diff --git a/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c b/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c index 43d782d62bd..c300dcb923e 100644 --- a/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c +++ b/gcc/testsuite/gcc.c-torture/compile/pr108688-1.c @@ -1,4 +1,4 @@ - +/* PR tree-optimization/108688 */ union U { signed int d : 7; signed int e : 2; } u; int a, b; @@ -12,4 +12,3 @@ foo (void) u.e ^= b; } } - diff --git a/gcc/testsuite/gcc.dg/pr108688.c b/gcc/testsuite/gcc.dg/pr108688.c new file mode 100644 index 00000000000..5f76f0ba83b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108688.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/108688 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-pre -fno-tree-fre -fno-tree-dominator-opts -fno-tree-loop-im -fno-code-hoisting" } */ + +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.d ^= b; + } +}