From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id AD3E13857C43 for ; Mon, 5 Jun 2023 05:53:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD3E13857C43 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com 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 354KeHLQ015673 for ; Sun, 4 Jun 2023 22:53:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=jQZW67Bdolyf5BtA0Uu8TpT5KA6b1Smd1cZCt0riwJM=; b=V9nu5/Rm1aam8+BrduAmoFNwYWbNQ8ZUc3iiX74FdDWjvtQy0GbT6Kvw89ztsFxMK2ds /c3ubrQjYmrOF/hv7QS1/ZmN3wPFze4hB8XOV7aCz+yGjoRgLnoFEgrk+LGmX2ZgyKE4 EnXKjzU+6Ltv6Sln1wAYsLUGIYt/eL3x1DTZq1lD7Rm/AFAeKKXuN2Etf69D/mArerYj 9L7B8ZhIyRBKHpjqvyxudEWudxG3W/a4KG3D8CtGLotdfZyN9n/Gyr19N2T2dGuzk0ID Ml6bDhqHcUQGI/Oy8jO2AkCGrrfVvCQ916d8TKAS8r1y2hN8i34r/oAs4W9nEOOoKd97 Ng== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3r02vpda1j-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 04 Jun 2023 22:53:56 -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.48; Sun, 4 Jun 2023 22:53:55 -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; Sun, 4 Jun 2023 22:53:55 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 458873F7050; Sun, 4 Jun 2023 22:53:55 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/2] Handle const_int in expand_single_bit_test Date: Sun, 4 Jun 2023 22:53:31 -0700 Message-ID: <20230605055331.2864335-2-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230605055331.2864335-1-apinski@marvell.com> References: <20230605055331.2864335-1-apinski@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: EKUe9KRsEwvP_f1Rtbkn16ehX2hlrHW9 X-Proofpoint-ORIG-GUID: EKUe9KRsEwvP_f1Rtbkn16ehX2hlrHW9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-03_08,2023-06-02_02,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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: After expanding directly to rtl instead of creating a tree, we could end up with a const_int which is not ready to be handled by extract_bit_field. So need to the constant folding here instead. OK? bootstrapped and tested on x86_64-linux-gnu with no regressions. PR middle-end/110117 gcc/ChangeLog: * expr.cc (expand_single_bit_test): Handle const_int from expand_expr. gcc/testsuite/ChangeLog: * gcc.dg/pr110117-1.c: New test. * gcc.dg/pr110117-2.c: New test. --- gcc/expr.cc | 10 +++++++--- gcc/testsuite/gcc.dg/pr110117-1.c | 31 +++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr110117-2.c | 7 +++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr110117-1.c create mode 100644 gcc/testsuite/gcc.dg/pr110117-2.c diff --git a/gcc/expr.cc b/gcc/expr.cc index ca008cd453e..868d812eb1a 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -12958,12 +12958,16 @@ expand_single_bit_test (location_t loc, enum tree_code code, rtx inner0 = expand_expr (inner, NULL_RTX, VOIDmode, EXPAND_NORMAL); + if (CONST_SCALAR_INT_P (inner0)) + { + wide_int t = rtx_mode_t (inner0, operand_mode); + bool setp = (wi::lrshift(t, bitnum) & 1) != 0; + return (setp ^ (code == EQ_EXPR)) ? const1_rtx : const0_rtx; + } int bitpos = bitnum; - scalar_int_mode imode = as_a (GET_MODE (inner0)); - if (BYTES_BIG_ENDIAN) - bitpos = GET_MODE_BITSIZE (imode) - 1 - bitpos; + bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos; inner0 = extract_bit_field (inner0, 1, bitpos, 1, target, operand_mode, mode, 0, NULL); diff --git a/gcc/testsuite/gcc.dg/pr110117-1.c b/gcc/testsuite/gcc.dg/pr110117-1.c new file mode 100644 index 00000000000..fd9a9e3268e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110117-1.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-vrp -fno-tree-ccp -fno-tree-forwprop" } */ +int a, b, d; +unsigned c; +int main() { + char e = -10; + int f = 1, g = 0; + if (a) { + char h = e; + i: + c = ~h - (-g & f || e); + int j = b % c; + g = j % 9; + if (c) { + if (d) + e = 0; + while (!g) + ; + int k = 0; + l: + if (k) + goto i; + } + } + if (e > -10) { + if (g) + f = 0; + goto l; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr110117-2.c b/gcc/testsuite/gcc.dg/pr110117-2.c new file mode 100644 index 00000000000..2e353258084 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110117-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-tree-dominator-opts -fno-tree-vrp -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre -fno-tree-copy-prop" } */ +int f() +{ + int t = 0; + return (t & 1) != 0; +} -- 2.31.1