From patchwork Sun Oct 10 23:19:37 2021 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: 46051 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FAA43858415 for ; Sun, 10 Oct 2021 23:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FAA43858415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633908015; bh=GLmD0BWA852gL2wQF4EFD6jLlMtyQLk0hADMe8dGrzc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=fon5ZV2cZO7zt2souNMArLZkBmzCoKNTUujRQZ1e10IBiTixM5S6tKWKUoWMWzXX8 hb8WeRxuY6ySiyjwFRNn+QYL442Jep/Wyom8odVEQ7QGPIIEAd/a+JMSq8apF8mEp3 O3CmOotg2kT/myx4bUMgR0qjJVldU+k30VYHItyc= 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 75A443858D28 for ; Sun, 10 Oct 2021 23:19:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75A443858D28 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19AMo6mE020702 for ; Sun, 10 Oct 2021 16:19:44 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com with ESMTP id 3bkrkt2fdj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 10 Oct 2021 16:19:44 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 10 Oct 2021 16:19:42 -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.18 via Frontend Transport; Sun, 10 Oct 2021 16:19:42 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id 78AD73F7040; Sun, 10 Oct 2021 16:19:42 -0700 (PDT) To: Subject: [PATCH] [GCC 10 branch] tree-optimization: [PR102622]: wrong code due to signed one bit integer and "a?-1:0" Date: Sun, 10 Oct 2021 16:19:37 -0700 Message-ID: <1633907977-26461-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: fWT3f25uRU8V1dm6PRWntq6R3zPyqqsm X-Proofpoint-ORIG-GUID: fWT3f25uRU8V1dm6PRWntq6R3zPyqqsm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-10_07,2021-10-07_02,2020-04-07_01 X-Spam-Status: No, score=-14.8 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski So here is the GCC 10 branch version which fixes the wrong code. The problem is we create a negation of an one bit signed integer type which is undefined if the value was -1. This is not needed for GCC 11 branch since the case is handled differently there and has been fixed there (and the trunk has now been fixed too). So for one bit types, there is no reason to create the negation so just setting neg to false for them, just works. OK? Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/102622 gcc/ChangeLog: * tree-ssa-phiopt.c (conditional_replacement): Set neg to false for one bit signed types. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/bitfld-10.c: New test. --- gcc/testsuite/gcc.c-torture/execute/bitfld-10.c | 24 ++++++++++++++++++++++++ gcc/tree-ssa-phiopt.c | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/bitfld-10.c diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c new file mode 100644 index 0000000..bdbf573 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/bitfld-10.c @@ -0,0 +1,24 @@ +/* PR tree-optimization/102622 */ +/* Wrong code introduced due to phi-opt + introducing undefined signed interger overflow + with one bit signed integer negation. */ + +struct f{signed t:1;}; +int g(struct f *a, int t) __attribute__((noipa)); +int g(struct f *a, int t) +{ + if (t) + a->t = -1; + else + a->t = 0; + int t1 = a->t; + if (t1) return 1; + return t1; +} + +int main(void) +{ + struct f a; + if (!g(&a, 1)) __builtin_abort(); + return 0; +} diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 9ed26a3..a6c197d 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -770,9 +770,12 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb, if ((integer_zerop (arg0) && integer_onep (arg1)) || (integer_zerop (arg1) && integer_onep (arg0))) neg = false; + /* For signed one bit types, the negation is not needed and + should be avoided and is the same as 1 case for non-signed + one bit types. */ else if ((integer_zerop (arg0) && integer_all_onesp (arg1)) || (integer_zerop (arg1) && integer_all_onesp (arg0))) - neg = true; + neg = TYPE_PRECISION (TREE_TYPE (arg0)) != 1; else return false;