From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id B6FEC3858C50 for ; Sat, 23 Jul 2022 06:09:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6FEC3858C50 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5EB84207B9 for ; Sat, 23 Jul 2022 06:09:43 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4E4BE13A92 for ; Sat, 23 Jul 2022 06:09:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0U0WE6eQ22LGcAAAMHmgww (envelope-from ) for ; Sat, 23 Jul 2022 06:09:43 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool Date: Sat, 23 Jul 2022 08:09:42 +0200 Message-Id: <2EE7DF73-91E1-40BB-B52A-D7FAF2A57B10@suse.de> References: In-Reply-To: To: "H.J. Lu via Gcc-patches" X-Mailer: iPhone Mail (19G71) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jul 2022 06:09:45 -0000 > Am 22.07.2022 um 22:17 schrieb H.J. Lu via Gcc-patches : >=20 > =EF=BB=BFOn Thu, Jul 21, 2022 at 4:24 AM Richard Biener via Gcc-patches > wrote: >>=20 >> The following makes sure to fold ~(a ^ b) to a =3D=3D b for truth >> values (but not vectors, we'd have to check for vector support of >> equality). That turns the PR106379 testcase into a ranger one. >>=20 >> Note that while we arrive at ~(a ^ b) in a convoluted way from >> original !a =3D=3D !b one can eventually write the expression this >> way directly as well. >>=20 >> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. >>=20 >> PR tree-optimization/106379 >> * match.pd (~(a ^ b) -> a =3D=3D b): New pattern. >>=20 >> * gcc.dg/pr106379-1.c: New testcase. >> --- >> gcc/match.pd | 6 ++++++ >> gcc/testsuite/gcc.dg/pr106379-1.c | 9 +++++++++ >> 2 files changed, 15 insertions(+) >> create mode 100644 gcc/testsuite/gcc.dg/pr106379-1.c >>=20 >> diff --git a/gcc/match.pd b/gcc/match.pd >> index 8bbc0dbd5cd..88a1a5aa9cc 100644 >> --- a/gcc/match.pd >> +++ b/gcc/match.pd >> @@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >> (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) >> (bit_not (bit_xor (view_convert @0) @1)))) >>=20 >> +/* ~(a ^ b) is a =3D=3D b for truth valued a and b. */ >> +(simplify >> + (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1)) >> + (if (!VECTOR_TYPE_P (type)) >> + (convert (eq @0 @1)))) >=20 > For integers, isn't it wrong to convert ~(boolean exp) to boolean exp? That=E2=80=99s what the (convert. =E2=80=A6) should compensate for? Richard=20 >=20 >> /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ >> (simplify >> (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2)) >> diff --git a/gcc/testsuite/gcc.dg/pr106379-1.c b/gcc/testsuite/gcc.dg/pr1= 06379-1.c >> new file mode 100644 >> index 00000000000..7f2575e02dc >> --- /dev/null >> +++ b/gcc/testsuite/gcc.dg/pr106379-1.c >> @@ -0,0 +1,9 @@ >> +/* { dg-do compile } */ >> +/* { dg-options "-O -fdump-tree-forwprop1" } */ >> + >> +_Bool foo (_Bool a, _Bool b) >> +{ >> + return !a =3D=3D !b; >> +} >> + >> +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) =3D=3D \[ba\]_\[0= -9\]+\\(D\\)" "forwprop1" } } */ >> -- >> 2.35.3 >=20 >=20 >=20 > -- > H.J.