From patchwork Fri Jun 9 17:27:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 70838 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 CC0A53856962 for ; Fri, 9 Jun 2023 17:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC0A53856962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686331718; bh=iYOFEA/IOnuPdQ14bUgqNBNX1KFe8hBox4QlKA73rVY=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=B6Q472asbBW/kHMyf6HP6qIn3xBnF9Cusqz05q3yNYD56knrWKY+S4nQ5Q+M/1M3I PL0BqTtu+6rJd0m+l7QUVpYEB5KZm02hQr+1kXDftC6JPU81O/poGWRr/G53f3LXQV 7hmV9UfNSYYvn/sNxgCOnzW0IHQjGx8itTAgJOBQ= 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 781D83858D3C for ; Fri, 9 Jun 2023 17:28:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 781D83858D3C 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 359FgAZX019928 for ; Fri, 9 Jun 2023 10:28:09 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3r30eu75rk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 09 Jun 2023 10:28:08 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 9 Jun 2023 10:28:06 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 9 Jun 2023 10:28:06 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 8CD653F7057; Fri, 9 Jun 2023 10:28:06 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Fix zero_one_valued_p not to match signed 1 bit integers Date: Fri, 9 Jun 2023 10:27:53 -0700 Message-ID: <20230609172753.3164342-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: XdsT93xNrY5e43P8dfJJNXETTk0dcKGY X-Proofpoint-GUID: XdsT93xNrY5e43P8dfJJNXETTk0dcKGY 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-09_12,2023-06-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, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 for GCC 13? Bootstrapped and tested on x86_64-linux-gnu with no regressions. 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. (cherry picked from commit 72e652f3425079259faa4edefe1dc571f72f91e0) --- gcc/match.pd | 10 ++++-- .../gcc.c-torture/execute/pr110165-1.c | 28 ++++++++++++++++ .../gcc.c-torture/execute/pr110166-1.c | 33 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 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 995ad98d823..91182448250 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1922,9 +1922,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (match zero_one_valued_p @0 - (if (INTEGRAL_TYPE_P (type) && tree_nonzero_bits (@0) == 1))) + (if (INTEGRAL_TYPE_P (type) + && (TYPE_UNSIGNED (type) + || TYPE_PRECISION (type) > 1) + && 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(); + } + } +}