From patchwork Fri Jun 9 01:47:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 105212 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp654765vqr; Thu, 8 Jun 2023 18:48:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qLVJ1GU1UwwZH40ADElSnN2KnLEmOOZqKOlKq5a2VB44FN0VP9YjM4/dv7/rRkA+/0+jY X-Received: by 2002:a50:ee07:0:b0:504:8014:1554 with SMTP id g7-20020a50ee07000000b0050480141554mr124762eds.28.1686275304848; Thu, 08 Jun 2023 18:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686275304; cv=none; d=google.com; s=arc-20160816; b=kGtCOBlvxjWN5qZb2nBxHgULZ/b8osxnLoliy94nStUdYoqVD3EZzlovzleuOkqZ7q tlFHul37/j3jQXiLhQxEFQOEl4f7h/Px7u0osT+VlxLgWigQkQ3htIy1p8LrUx8SHb6M tOnXB4dJNkVYhi2ZdkAxhvw+3ZcKhkVsU011PEMhZSHxUZu8MK33ThV5F8ukkxPEbDU9 SBDK9PlsyB3eSrv99AiB93I0Tb4Trx0nUwgJFKwqt1LXuqp3teCeQuSvuoBGbpR9Et9b aj9azNF4pTOL3rpmM3q8N7VkMNHlFGZpwjKAn0CVqWT4hmkd9KI95MXvRjSVLqFBXBTD 3u0Q== 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=bXqlk4DO49OMsjZsNpxpxZ3Dh/APfkWWjH0a/DsZ7BM=; b=VcYtyPrCD8L6kuLJPOiXIccylxsrdwYfusHUbgRyOw7U5UnrJFnuVYuKTHFh0dkeU/ mn2igbvYzROIqLZDOAMjvOGIXasEgQzwrgdIOp6DjltZ0+MveqcisShzgfNPm8LvlfBn lhETTvBCQ9nW17QqagIS4dizbP9JydeAcT3FTW9qQFW26VaFUm2v4//0P9cVf9dHeIaL z2uU8obtjvALWK3Yf7rWDaWOOY2l50PHazoamQSjCIkabr81bahv7RJIT5pAC4hy9kpu v7rvURSyBSYTUtfzPBdBUw246mQXjBHc7wQe5wb3XdQwYTDML9M2EJ5lzQoYOIu9Cjpp 2g/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JrvYu9y7; 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 d7-20020a056402078700b00514f06a2b68si1560306edy.346.2023.06.08.18.48.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:48:24 -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=JrvYu9y7; 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 08DAE3857708 for ; Fri, 9 Jun 2023 01:48:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08DAE3857708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686275301; bh=bXqlk4DO49OMsjZsNpxpxZ3Dh/APfkWWjH0a/DsZ7BM=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JrvYu9y752RA2CRmuYI5pUJXT6CbwnQULayn0T5CA2izBOICnzpZXBe+yQudrMQiY J74ZxNLTCnbjl7/guxVgriycjOE+TxGBiAd+hwnrkg9NVSZRlibEp7YoxYGceWiI1f HJPh+tWbfs8hsSgwLtFFpwuJc2H3OlJLljfLSYLo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 4E846385702B for ; Fri, 9 Jun 2023 01:47:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E846385702B Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 358NXfu9015422 for ; Thu, 8 Jun 2023 18:47:21 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r30eu4yuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 08 Jun 2023 18:47:21 -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; Thu, 8 Jun 2023 18:47:19 -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; Thu, 8 Jun 2023 18:47:19 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 1E7DF3F70B6; Thu, 8 Jun 2023 18:47:17 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Fix zero_one_valued_p not to match signed 1 bit integers Date: Thu, 8 Jun 2023 18:47:01 -0700 Message-ID: <20230609014701.3123763-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: eUYmxcjwdJ-Z1xeajVxrL2WSCi23D9W1 X-Proofpoint-GUID: eUYmxcjwdJ-Z1xeajVxrL2WSCi23D9W1 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-08_18,2023-06-08_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, 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?1768187813981543562?= X-GMAIL-MSGID: =?utf-8?q?1768187813981543562?= So for the attached testcase, we assumed that zero_one_valued_p would be the value [0,1] but currently zero_one_valued_p matches also signed 1 bit integers. This changes that not to match that and fixes the 2 new testcases at all optimization levels. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Note the GCC 13 patch will be slightly different due to the changes made to zero_one_valued_p. PR tree-optimization/110165 PR tree-optimization/110166 gcc/ChangeLog: * match.pd (zero_one_valued_p): Don't accept signed 1-bit integers. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr110165-1.c: New test. * gcc.c-torture/execute/pr110166-1.c: New test. --- gcc/match.pd | 13 ++++++-- .../gcc.c-torture/execute/pr110165-1.c | 28 ++++++++++++++++ .../gcc.c-torture/execute/pr110166-1.c | 33 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110165-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110166-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 4ad037d641a..9a6bc2e9348 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1984,12 +1984,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) @0) /* zero_one_valued_p will match when a value is known to be either - 0 or 1 including constants 0 or 1. */ + 0 or 1 including constants 0 or 1. + Signed 1-bits includes -1 so they cannot match here. */ (match zero_one_valued_p @0 - (if (INTEGRAL_TYPE_P (type) && wi::leu_p (tree_nonzero_bits (@0), 1)))) + (if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || TYPE_PRECISION (type) > 1) + && wi::leu_p (tree_nonzero_bits (@0), 1)))) (match zero_one_valued_p - truth_valued_p@0) + truth_valued_p@0 + (if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || TYPE_PRECISION (type) > 1)))) /* Transform { 0 or 1 } * { 0 or 1 } into { 0 or 1 } & { 0 or 1 }. */ (simplify diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c new file mode 100644 index 00000000000..9521a19428e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110165-1.c @@ -0,0 +1,28 @@ +struct s +{ + int t : 1; +}; + +int f(struct s t, int a, int b) __attribute__((noinline)); +int f(struct s t, int a, int b) +{ + int bd = t.t; + if (bd) a|=b; + return a; +} + +int main(void) +{ + struct s t; + for(int i = -1;i <= 1; i++) + { + int a = 0x10; + int b = 0x0f; + int c = a | b; + struct s t = {i}; + int r = f(t, a, b); + int exp = (i != 0) ? a | b : a; + if (exp != r) + __builtin_abort(); + } +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c new file mode 100644 index 00000000000..f999d47fe69 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110166-1.c @@ -0,0 +1,33 @@ +struct s +{ + int t : 1; + int t1 : 1; +}; + +int f(struct s t) __attribute__((noinline)); +int f(struct s t) +{ + int c = t.t; + int d = t.t1; + if (c > d) + t.t = d; + else + t.t = c; + return t.t; +} + +int main(void) +{ + struct s t; + for(int i = -1;i <= 0; i++) + { + for(int j = -1;j <= 0; j++) + { + struct s t = {i, j}; + int r = f(t); + int exp = i < j ? i : j; + if (exp != r) + __builtin_abort(); + } + } +}