From patchwork Thu Jul 21 11:23:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 105 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e252:0:0:0:0:0 with SMTP id bl18csp1393974wrb; Thu, 21 Jul 2022 04:24:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sgskwq4G9iVVO0tqQOIrVvR0h2Y6TvKJfbY95k+P1KZTrjx7Nv2qUrCQxBCVluh4zQZ55X X-Received: by 2002:aa7:d155:0:b0:43a:bc8d:8d75 with SMTP id r21-20020aa7d155000000b0043abc8d8d75mr56485401edo.322.1658402674484; Thu, 21 Jul 2022 04:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658402674; cv=none; d=google.com; s=arc-20160816; b=N36KSN2Qco0eerBXuvgC/oYuE5e28+6RJ9FBtvKRNfTsAtrpgFiigOGi602r46sQr7 ZfHLMb+KZ7QWl0uLe82eI+hCmJ3pLgRfPx3V+qAvhnU6uhCdrnqUp/xnjqXUswNkGBD2 zexkrSG4znYgjQKum5LnjoGAC7T91J28ZW3vq9mLseqogFdDecHIYMo4HVf6HnwfA9wi 5tPdqkrFwPE6F75rHqAd13KlNcX8Bcv23WGk7qrA4cOUXdMbxsy4aZ3TBWyueUpfamFu RVVuycpwZ3v/IQWB6W/03AMRsoLZrx7bzN4ugZzoe2zdrtWHw+UyJmTA6jtBZ+maZzM8 mwRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=pkwpi02RYG54LpMzw2T6DDwtedlIgolNmi1o3sMewlg=; b=lsj46xWIMTDk+AZtKCh5VM3gvPjD2XfZ0WiOP+p/bo6rtodsGqYp6D2IIMLuDZiMSC B18XKrteNDXTvCJFY6K7mNypfx51rmChb14OPgqy7lBKL5Fd2nz+ZEvsU6K0twzVypQl uEITKzsh472r3q8w7z+PwMLuvl6umkFrpJhJNAr7aK+m6nHFUdtEL7XNoiGBYzQ9XKMv 9Voy8u2QZ5+CP1KhWe5R/28ZF9YMBOdlcAULGVl8Ps5PMjIH4EL2jsKl6C9vMQcsq5Fz XnEOrHxESdzG/8H954jVdg8q4ILuzqkXinxlabEOGbURZnlttzRHNBtxVenTx4wAwMrf pL1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="t/UvuFDj"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x22-20020aa7d6d6000000b0043bb815dc95si1771473edr.340.2022.07.21.04.24.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 04:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="t/UvuFDj"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEBD0385BAFC for ; Thu, 21 Jul 2022 11:24:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEBD0385BAFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658402662; bh=pkwpi02RYG54LpMzw2T6DDwtedlIgolNmi1o3sMewlg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=t/UvuFDjEzwHQGn+CjuOLgAr6S/cQ0CZiuaHTg9zXsev6ZCcB0iGdEU5EXRsd9qAK 7ojW1sx1Cq7pARR8ODN576NbjqLXcNAIfNgAcC9XAOhXeR8TmQeAnBOnRmtXJAdetC Ilou684tWzyQwIl2tYlFkLt1gAmkgXQfOSbg2b7M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A4AB83858D28 for ; Thu, 21 Jul 2022 11:23:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4AB83858D28 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-out1.suse.de (Postfix) with ESMTPS id 929E4346B4 for ; Thu, 21 Jul 2022 11:23:38 +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 7CEC113A1B for ; Thu, 21 Jul 2022 11:23:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id plgSHTo32WJJbAAAMHmgww (envelope-from ) for ; Thu, 21 Jul 2022 11:23:38 +0000 Date: Thu, 21 Jul 2022 13:23:38 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool MIME-Version: 1.0 Message-Id: <20220721112338.7CEC113A1B@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-12.1 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1738961242657761019?= X-GMAIL-MSGID: =?utf-8?q?1738961242657761019?= The following makes sure to fold ~(a ^ b) to a == 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. Note that while we arrive at ~(a ^ b) in a convoluted way from original !a == !b one can eventually write the expression this way directly as well. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106379 * match.pd (~(a ^ b) -> a == b): New pattern. * 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 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)))) +/* ~(a ^ b) is a == 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)))) + /* (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/pr106379-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 == !b; +} + +/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) == \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */