From patchwork Sat Sep 2 02:32:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 137415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp1258270vqu; Fri, 1 Sep 2023 19:33:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8861AMrqIU+mJxFCmaZ1PH7lveTDeFR3W2FQsYl++zKYg14nCMsDfF4UMZuDNI29Tx2VX X-Received: by 2002:a17:906:51d7:b0:9a2:15d3:2583 with SMTP id v23-20020a17090651d700b009a215d32583mr2646881ejk.2.1693622019150; Fri, 01 Sep 2023 19:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693622019; cv=none; d=google.com; s=arc-20160816; b=Fk3jO5lQJvU6ng+2KKVpH1M4bpnXlAQESvbuajIw9DERdYtvbnyqEP7r6/nKNgUTiQ ZxFvZRHjuy9WCZkbIDftuXn4gyGPtWqFm7CYgrX5eNtON6B5VDPi2yLg/71FJDvIEiig Ymv7NIZEpjy8j/dIfonUfbxUnJxDXSm4cVK1kGcnxdEGnYEVl7M9wPpYY7jNsYw93mc2 cHF4j46skzoAcPBJv3mXd3WCEdTjpGlbuAE5nnPZgogvD+r2dFAiiWDUlWLpgcXDhONI BO3e+3+xkUlHrjMEVwlCnTKRTVfUq837tKwA7p58CzoopFjPm4OqSt2/KqLKWnvSSYOQ t+ag== 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=rFeZ8Gc1ExCuRNnpi67OhLK+/iw2h5RyrmVP8wdFsaE=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=plUZJQPdYQvFb7R2EOfrVO6q8Gg2cuHhuyEDKGbDDuKiNdxy/uF+0U9mtFssp0J+af rlRgolO2WMSX2u/pdm3dmPs+T1oFnnZx7+rhiR6xbPLmFoi5Lqr2xvyxWe6OFE1BFvc1 naFQub5shFYWPiuoM7h2j3/QKPPJwoHQTEi+qtGORqfTrk2RfH1Jn5hz9FWB8y0tCOlI CeoZ6+b6oPeI9GCmQfTxrnDkhkplP6fGsQCMRxNkb3ZvCV12Sc4DqQRuO069skqcRLiJ EtP/2Ux3Qi6OQ3GZcsecfOlLdYSwMWbXGJVjhgszyJecKlPgp6UteDsxW0ODhRctGEvq 8T1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="hL/98s5C"; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id re20-20020a170906d8d400b0098843bd4387si3582267ejb.320.2023.09.01.19.33.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 19:33:39 -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="hL/98s5C"; 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 91F97385783F for ; Sat, 2 Sep 2023 02:33:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91F97385783F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693622015; bh=rFeZ8Gc1ExCuRNnpi67OhLK+/iw2h5RyrmVP8wdFsaE=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hL/98s5CxwpQgfQHJSMrtnFqw9jH08hwACxoHHftf/s2fMJHQkzE/3OPELZf2B9KR UW6OLyAbw/UBGew7y34lYNTYnWghU3UFRsni2z5MqOSLAj+ZhIlR/pd2rXSt3uFyzE EswmtwhjcpRuIZ5UfyDM+xzMyFkeYgp0wlMZ7FO4= 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 C0E3D3857738 for ; Sat, 2 Sep 2023 02:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0E3D3857738 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 3821kAp3009401 for ; Fri, 1 Sep 2023 19:32:48 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sucjvtxsj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 01 Sep 2023 19:32:48 -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, 1 Sep 2023 19:32:46 -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, 1 Sep 2023 19:32:46 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id F29193F704A; Fri, 1 Sep 2023 19:32:45 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] ssa_name_has_boolean_range vs signed-boolean:31 types Date: Fri, 1 Sep 2023 19:32:38 -0700 Message-ID: <20230902023238.814338-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: rhuUpFAR2xwb3Q-64ot--15p--BZzgko X-Proofpoint-ORIG-GUID: rhuUpFAR2xwb3Q-64ot--15p--BZzgko X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-02_01,2023-08-31_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 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.30 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: INBOX X-GMAIL-THRID: 1775891402614951947 X-GMAIL-MSGID: 1775891402614951947 This turns out to be a latent bug in ssa_name_has_boolean_range where it would return true for all boolean types but all of the uses of ssa_name_has_boolean_range was expecting 0/1 as the range rather than [-1,0]. So when I fixed vector lower to do all comparisons in boolean_type rather than still in the signed-boolean:31 type (to fix a different issue), the pattern in match for `-(type)!A -> (type)A - 1.` would assume A (which was signed-boolean:31) had a range of [0,1] which broke down and sometimes gave us -1/-2 as values rather than what we were expecting of -1/0. This was the simpliest patch I found while testing. We have another way of matching [0,1] range which we could use instead of ssa_name_has_boolean_range except that uses only the global ranges rather than the local range (during VRP). I tried to clean this up slightly by using gimple_match_zero_one_valuedp inside ssa_name_has_boolean_range but that failed because due to using only the global ranges. I then tried to change get_nonzero_bits to use the local ranges at the optimization time but that failed also because we would remove branches to __builtin_unreachable during evrp and lose information as we don't set the global ranges during evrp. OK? Bootstrapped and tested on x86_64-linux-gnu. PR 110817 gcc/ChangeLog: * tree-ssanames.cc (ssa_name_has_boolean_range): Remove the check for boolean type as they don't have "[0,1]" range. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr110817-1.c: New test. * gcc.c-torture/execute/pr110817-2.c: New test. * gcc.c-torture/execute/pr110817-3.c: New test. --- gcc/testsuite/gcc.c-torture/execute/pr110817-1.c | 13 +++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr110817-2.c | 16 ++++++++++++++++ gcc/testsuite/gcc.c-torture/execute/pr110817-3.c | 14 ++++++++++++++ gcc/tree-ssanames.cc | 4 ---- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110817-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110817-2.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110817-3.c diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c new file mode 100644 index 00000000000..1d33fa9a207 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-1.c @@ -0,0 +1,13 @@ +typedef unsigned long __attribute__((__vector_size__ (8))) V; + + +V c; + +int +main (void) +{ + V v = ~((V) { } <=0); + if (v[0]) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c new file mode 100644 index 00000000000..1f759178425 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-2.c @@ -0,0 +1,16 @@ + +typedef unsigned char u8; +typedef unsigned __attribute__((__vector_size__ (8))) V; + +V v; +unsigned char c; + +int +main (void) +{ + V x = (v > 0) > (v != c); + // V x = foo (); + if (x[0] || x[1]) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c b/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c new file mode 100644 index 00000000000..36f09c88dd9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr110817-3.c @@ -0,0 +1,14 @@ +typedef unsigned __attribute__((__vector_size__ (1*sizeof(unsigned)))) V; + +V v; +unsigned char c; + +int +main (void) +{ + V x = (v > 0) > (v != c); + volatile signed int t = x[0]; + if (t) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc index 23387b90fe3..6c362995c1a 100644 --- a/gcc/tree-ssanames.cc +++ b/gcc/tree-ssanames.cc @@ -521,10 +521,6 @@ ssa_name_has_boolean_range (tree op) { gcc_assert (TREE_CODE (op) == SSA_NAME); - /* Boolean types always have a range [0..1]. */ - if (TREE_CODE (TREE_TYPE (op)) == BOOLEAN_TYPE) - return true; - /* An integral type with a single bit of precision. */ if (INTEGRAL_TYPE_P (TREE_TYPE (op)) && TYPE_UNSIGNED (TREE_TYPE (op))