From patchwork Thu Aug 10 00:19:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 133625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp91354vqi; Wed, 9 Aug 2023 17:21:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1k0Larb7sAdF2vc2yf6CvQUOC5a0qrtrUu3UjT1urp2ShU5AOW570ME7xF/fbQ8/NIalY X-Received: by 2002:a05:6512:b91:b0:4fe:a5c:efa3 with SMTP id b17-20020a0565120b9100b004fe0a5cefa3mr678176lfv.62.1691626899269; Wed, 09 Aug 2023 17:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691626899; cv=none; d=google.com; s=arc-20160816; b=ansmEDrpYbhzJqLy9vTILy6A2fS7QcKPSkmYAON7Yn29fKovhBRNf5RzsvrgbhPvDh +lPqQ4FVURU+34EbvBOaw4JCTxMlvCi+XbgR8NX2es0hvgwARgEpH8VwalmxAbMJeudq zplyVrBr6SkHlZx4VaFDwNC+1uF1Rn1RYur+5MfROsutWsamCKLOAiXYZB8yDbl2SHQR MGzYqTf3FrVOsMdjKvZxihftmoHXQcExRibLzPvhOo+VZcImuiza9NA4enDAlToZ/gQu AYEXd2X9sMbC1ak22rPiBMffw8d9pP/MQdZcdtTk2TLT8fOumDGKqoppL3xg305Gs9wo juIQ== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vRrHPBSnKacpOtWEZuK6jttnayiZirUhX9UA2Ql2GdQ=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=t7tgrzYMKTUcVDTIkTYWsXJh6dhjBsg2t6zvSTnGC4S4l1ck3YJvE+1MxTd7XxqGWI y8dLEmg2vDtT5+MwxdIOsx0dK5r7kGLlB9M8qgXKWafy3lZtxLSkr33lUe9EniXPtbRb T1XGsK0QKavmN2n3ugbAk0m+BNZx1di4L0gDhSfzb+rO0QS5A2eomFv1i7F7WaPORGUb udHTL1ywR74OtteRy/RjVQ0+N2A5HCPKbI0V++UxpfT4TSjcYy6vxRyjCdBNMgUbRwr2 zWWvyWOm0UJ6+DyY9OfZn2bOVciRr6k9yRH/eop4WCWzF1nhNDTmDKJDj5BxyTPNom/h qWqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YkDU7KtI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t17-20020aa7d711000000b005222d573a77si275259edq.158.2023.08.09.17.21.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 17:21:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YkDU7KtI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 24A4B3857725 for ; Thu, 10 Aug 2023 00:21:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24A4B3857725 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691626889; bh=vRrHPBSnKacpOtWEZuK6jttnayiZirUhX9UA2Ql2GdQ=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YkDU7KtIGNDxy3ECVoqiCZmGPmI+dRxakvmQMJpKsfFBB+pnmu8U8D9MpDctNCx4t LXnTm14/Kt+eOsN81+elRSwW/uXVJs4hghVmrTIdC+YPlo+TOksXUO9Uo3FxAjA2SO c7xU1jIh5glIA0UO6usI59wrmZS1DrvpaZvLczKA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 1136E3858D33 for ; Thu, 10 Aug 2023 00:20:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1136E3858D33 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 379GsilQ023142 for ; Wed, 9 Aug 2023 17:20:20 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sc57skwh4-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 09 Aug 2023 17:20:20 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 9 Aug 2023 17:20:07 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 9 Aug 2023 17:20:07 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 48EFE5B6935; Wed, 9 Aug 2023 17:20:07 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Fix PR 110954: wrong code with cmp | !cmp Date: Wed, 9 Aug 2023 17:19:56 -0700 Message-ID: <20230810001956.2680884-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: zsUn8_1QZ5VBjAlX69gS9NuyiFNEnBbU X-Proofpoint-ORIG-GUID: zsUn8_1QZ5VBjAlX69gS9NuyiFNEnBbU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-09_20,2023-08-09_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773799367664302406 X-GMAIL-MSGID: 1773799367664302406 This was an oversight on my part not realizing that comparisons in generic can have a non-boolean type. This means if we have `(f < 0) | !(f < 0)` we would optimize this to -1 rather than just 1. This patch just adds the check for the type of the comparisons to be boolean type to keep the optimization in that case. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR 110954 gcc/ChangeLog: * generic-match-head.cc (bitwise_inverted_equal_p): Check the type of the comparison to be boolean too. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr110954-1.c: New test. --- gcc/generic-match-head.cc | 3 ++- gcc/testsuite/gcc.c-torture/execute/pr110954-1.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110954-1.c diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc index ddaf22f2179..ac2119bfdd0 100644 --- a/gcc/generic-match-head.cc +++ b/gcc/generic-match-head.cc @@ -146,7 +146,8 @@ bitwise_inverted_equal_p (tree expr1, tree expr2) && bitwise_equal_p (expr1, TREE_OPERAND (expr2, 0))) return true; if (COMPARISON_CLASS_P (expr1) - && COMPARISON_CLASS_P (expr2)) + && COMPARISON_CLASS_P (expr2) + && TREE_CODE (TREE_TYPE (expr1)) == BOOLEAN_TYPE) { tree op10 = TREE_OPERAND (expr1, 0); tree op20 = TREE_OPERAND (expr2, 0); diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110954-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110954-1.c new file mode 100644 index 00000000000..8aad758e10f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110954-1.c @@ -0,0 +1,10 @@ + +#define comparison (f < 0) +int main() { + int f = 0; + int d = comparison | !comparison; + if (d != 1) + __builtin_abort(); + return 0; +} +