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: 105742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1071356vqr; Fri, 9 Jun 2023 10:28:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xLmEcqbFydq8h0feaZMsb6NUc8JI1E8eJKdFNYS9q4YuJoWPvgqVkg0K/IDBC4q5QzZvB X-Received: by 2002:a17:907:5cc:b0:96a:9467:1dc7 with SMTP id wg12-20020a17090705cc00b0096a94671dc7mr1918811ejb.25.1686331734710; Fri, 09 Jun 2023 10:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686331734; cv=none; d=google.com; s=arc-20160816; b=h5qZ+v8IdnuLhI+KBJngw5efZml+InG60HaHWyYR1qjJbDZrAPPS6b9iATysiLf23C 52jtOB1dUgeLVflyF/gPDnqGQBBqEueYeBALVqA1CRbr/KmkHUe/jFvmkRvz65TjAAtc n5MV7H2AV7emFUulAQuGuGgrxfxRv3QiK6YS34eqfp5/H3q2H4PuwOKL54kulN35LuM0 QUh+NaEZLqcvWeCYdj46GJj5MuPnl37rLKlrY4Z/8MZIDUSilqAvP3xSUIYfgjBhWYBY dcORAscdEHe/z9NG8rG2jAoZHafAVyLXoh9+PkIG4hEJUkxhdPkaRl8MNUPk9IJjaqUZ kVFw== 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=iYOFEA/IOnuPdQ14bUgqNBNX1KFe8hBox4QlKA73rVY=; b=sqZizzDRge7e7Wovk8UxW0slwKY7TCSEA0T6jhrzD14XPn1NQFaHFcdHQ2FZTeWQgX jYvS09m/XcReKV17pLCT5sH46DU0a6dnYwPKxHguOavDy6mdFa38pBnNJYZIAtX2VADw aqnA9a94xsW+vsK6ncR43bCXC+CWNvdtH/ruvaEPlp7ak5/n7/1YgHfC6bhb94KwXRmQ umXuQ6if7LeWXz0j0EqtqkzZQ+ue5cKa8Bo0sTJMVDZ1pMbYblN258MPDk2kHYYIHH6t +g+uMlXk+uoZsBS19UlMy54+EhzaJ8d3+CO+/rniJgv9WUDENn3A0s29nFXEQzxd3z19 ONRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xTc0mdL9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h17-20020a170906719100b00977383b2951si1593570ejk.827.2023.06.09.10.28.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 10:28:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xTc0mdL9; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 9383B3857353 for ; Fri, 9 Jun 2023 17:28:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9383B3857353 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686331733; 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=xTc0mdL9D0ON+0RCkXXIgH3Bso8hq7pjCTuXNY7DvrhZcoSDAHSrHttfN246A2hHD slEbya5s0DwZtEXbunahv6haoGZv1ZDzC2jQ8SY9SDdgK1fBjlGi3M9Eda0k7z0xcy Fx9ozUOZNNhitDNqw1oyGMQ8sIciNwVC2tMVJqCo= 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+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?1768246984939437025?= 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(); + } + } +}