From patchwork Mon Jul 25 11:01:36 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: 155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp1577260pxt; Mon, 25 Jul 2022 04:02:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ut8Wr0Iu2qUBBqVaHmi4ni8eI+aFioTQvczmsYfl5wAaJNemLMNrCMtc+SZzSHMsZ8Ilpt X-Received: by 2002:a05:6402:370c:b0:435:cb14:9aa8 with SMTP id ek12-20020a056402370c00b00435cb149aa8mr12477611edb.35.1658746952139; Mon, 25 Jul 2022 04:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658746952; cv=none; d=google.com; s=arc-20160816; b=MmF+nH2DnyERKnO7yoFBSsOKaIeCotN1WzT5yoouwBeVhcQcjvUx4Oz0jzKmxKy5cn 71+TrdeoZ82ELRbdHJmTPSbX9peXdCVJVuoti/X5Cfw78a/V/FKZ+lQZlBazTcp+N6a1 bPwGoSxAKhPGi6gdIaA6uSyt0hqiXMNdU6rDcX2NyNJC/MHONaNUrFovD0jhWF6R+8hV HQU5gRiep12rlUTErSOC/E0a/yydW2mB3QHYeCcAKABSa1MfuKwApGoCG4ze0Fab95SN o9z+P/P+VYezO9+r3kPUq4KZuJgNOBegrcSq/g44nlVbJZh8F8gaqE4BZI6NXtKPOdI5 ZvVA== 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=2Cf3FAEqVSQoh+VhurhPyqAPXeZq2/jgetHNGfknubU=; b=q5BBxsjrsHxuFt4/1l1YlQo51T+EVXxLBdOL1n2A0nxRHhtrMm05ZSNgG5GnO0hwz1 DyxMVNgJXkwWfJe1Ecl/PJZPuPovVogNOaSun/+B4j8DScSD5i/IgRPQ2O/RCMEIG353 tBp2oN1TPaTyC/npZ18TcMBMYnH79LpNVDhSIhmsBsXmbVzOLtgmUpu+z08WpIPB8vLx P9HpErQHfa8kZdmn22TnFVGBwkp+2M2ADJrCQR6wq6Vp4kjZL600QoHSHp/qcmt8J0ia VOkK44HvnQLZqse8DGGanSUd0H3jSxgrnltDGpsKsylSpj+HJ/aoyFi6/CmdisSxvSVv o2iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ou+h7kDl; 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 x9-20020aa7d389000000b0043a72951a14si10969906edq.304.2022.07.25.04.02.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 04:02:32 -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=Ou+h7kDl; 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 17327385736D for ; Mon, 25 Jul 2022 11:02:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17327385736D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658746951; bh=2Cf3FAEqVSQoh+VhurhPyqAPXeZq2/jgetHNGfknubU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ou+h7kDlLCm0b/SBRDFyMlZ4tfdw6oLp5qiPMnLOglSL+uB/vVTMiMhjvUi/BVFeH 0+0XgMdQUsnFlHxx8i+5JwUfBYGloBijwMu6QbHoh2IqeIn81qSlgx1MNSlFr+ygjI FiugthXAgaiFli3U4mP75XePxLHfDpW5o3q1sEpg= 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 2DF20383F957 for ; Mon, 25 Jul 2022 11:01:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DF20383F957 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 0D94234540 for ; Mon, 25 Jul 2022 11:01:37 +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 EE8DC13ABB for ; Mon, 25 Jul 2022 11:01:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8GgOORB43mIpOwAAMHmgww (envelope-from ) for ; Mon, 25 Jul 2022 11:01:36 +0000 Date: Mon, 25 Jul 2022 13:01:36 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/106414 - fix mistake in ~(x ^ y) -> x == y pattern MIME-Version: 1.0 Message-Id: <20220725110136.EE8DC13ABB@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?1739322244021581215?= X-GMAIL-MSGID: =?utf-8?q?1739322244021581215?= When compares are integer typed the inversion with ~ isn't properly preserved by the equality comparison even when converting the result properly. The following fixes this by restricting the input precisions accordingly. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR middle-end/106414 * match.pd (~(x ^ y) -> x == y): Restrict to single bit precision types. * gcc.dg/torture/pr106414-1.c: New testcase. * gcc.dg/torture/pr106414-2.c: Likewise. --- gcc/match.pd | 3 ++- gcc/testsuite/gcc.dg/torture/pr106414-1.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/torture/pr106414-2.c | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106414-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr106414-2.c diff --git a/gcc/match.pd b/gcc/match.pd index 9736393061a..330c1db0c8e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1946,7 +1946,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* ~(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)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) == 1) (convert (eq @0 @1)))) /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ diff --git a/gcc/testsuite/gcc.dg/torture/pr106414-1.c b/gcc/testsuite/gcc.dg/torture/pr106414-1.c new file mode 100644 index 00000000000..097471617b4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106414-1.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +int a, c, e; +const int b = 1; +char d; +int main() { + a = ~(e || 0) ^ b & ~d; + d = ~(a | ~2); + if (d) + __builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr106414-2.c b/gcc/testsuite/gcc.dg/torture/pr106414-2.c new file mode 100644 index 00000000000..bed6a40c61e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106414-2.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +int a, b, c, d; +unsigned e; +int main() { + c = e = -((a && 1) ^ ~(b || 0)); + if (e < -1) + d = c; + if (!d) + __builtin_abort(); + return 0; +}