From patchwork Mon Jun 5 05:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 103087 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2473688vqr; Sun, 4 Jun 2023 22:54:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4iZsw1trKjyqy/Toe8OU+joLaBokg1nu8QWwEvw5AvUqEeHXw4uR+5UeS3t26G7iAMmXPG X-Received: by 2002:a05:6402:4308:b0:514:5595:69b3 with SMTP id m8-20020a056402430800b00514559569b3mr8363248edc.4.1685944491657; Sun, 04 Jun 2023 22:54:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685944491; cv=none; d=google.com; s=arc-20160816; b=imkSqk840RDaGAHNa1ulskbohaGqc1S4EIWlBwaay//prqu4gYqnz1nmfqWgalkPGb 1SsOhF914TnhYZ/hc2o+Ivg7wB4q9yfehcK9J2+5MrJFbBRkhwIoWvCedjz+3PElcObz zN1faOKRfJS8F6y0o7EqbniLUpjFiKXQbtqjd/N7OnteJYIhZUiblfwDbSBVZAzsOqJN QhzpPKCoUNuvm639HCJtV2AkoPL1UmXBK0goELiGwcyD5XCvbI7dtU9X52qcqi/F1uSe y0NF3UFRL08rvH5h25XwNeYkFRUlLX6k73yi0BbBHldlGvZOMDF3kFPHP+KKeCF5wGkC lUSg== 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:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=jQZW67Bdolyf5BtA0Uu8TpT5KA6b1Smd1cZCt0riwJM=; b=Vp5nqDZ7gR6iT5/GL+iDA9Y7acPgwO458SQ/3WUHm430aPUtTrsFOIWo79G4xPHEoT Z0tFv+3Wgl53HFlYjHQIynJyzTPkpe/Z17KsLA7hSyhQIi7GksQtgSVxvQO9fwg5RiAK N1ue55GOSV/Y5r+ccCGEuSwnNarY/g5B1REBqUnjsDgRaTAvyIy0iXFuB692n3OArMVs 8Dyz/UpMZ2cHBPERu9vOPG1wWRM9OBgsd/MGIuoUOYpL9UmZ/gXPECQjlA++qQzc3fPJ jzyfQ2Q2/Z3jXnktLM7kwzUBEAxoBIybYkhzJKmJ5iqsGxvpnCTppiap1ci6O7vRPlnc pbEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JmO8oiq0; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k11-20020a05640212cb00b00514a417f159si4504671edx.202.2023.06.04.22.54.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jun 2023 22:54:51 -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=JmO8oiq0; 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 216483856625 for ; Mon, 5 Jun 2023 05:54:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 216483856625 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685944481; bh=jQZW67Bdolyf5BtA0Uu8TpT5KA6b1Smd1cZCt0riwJM=; h=To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=JmO8oiq0ayhNBfbIYt/UUiJpSpjxhd+akfZY/ICaLYr5ULqNMbYp4TH2hXeNiE5l8 SjQ294iTRfPF2VetSw+oFKxJ8i0EL6ddhBff4z8jwaivrcOspuiDS94qTQ2Y9eMW71 uPTpy68CUfMCIsGFMOoIsSPX8ZmVaj7t1/+e5mZU= 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 AD3E13857C43 for ; Mon, 5 Jun 2023 05:53:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD3E13857C43 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 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) 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 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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767840931571106867?= X-GMAIL-MSGID: =?utf-8?q?1767840931571106867?= 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; +}