From patchwork Wed Oct 11 00:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1846190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=Be0L8yjV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S4v361jgXz1yq4 for ; Wed, 11 Oct 2023 11:36:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71F2B3858404 for ; Wed, 11 Oct 2023 00:36:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 420EE3858C41; Wed, 11 Oct 2023 00:36:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 420EE3858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39B0Yal7010804; Wed, 11 Oct 2023 00:36:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=FipaRC2cDbIaCwnP/Zwjjr6DbUosakLyDuatV4SaUHk=; b=Be0L8yjVB3j1j1WEjb8PWFzsNkZpAQlssPOuuZmV5YP5HCn1B3oU/ax5FxuSkYEikKzB 9fMmSant5yVCupF2FncV2r6EiboOqJsgzwz2gwZ+hWdbDQgnc8jGjHYgrmSufv5LWh2e j6pmdeUXA3rBLNEbxsAcawxexPA4cxtYDs2k0sanpdx7N/TvTUPHV0bylOr13BHxt0sU LCOPz/cpZNk+UbkiKMqQp+rjaHoxWvPvz8O5hIxLztyhxDzKDkpTCUplPbKPXvRUKB4L 5YtFeuZQVn+nyOEpymf8NT0xcWKU41xi3WfRblez65atMRQUfQuvqmO9DBDSU930cjgl Qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tnh9k01qu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 00:36:10 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39B0ZX99013881; Wed, 11 Oct 2023 00:36:10 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tnh9k01pb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 00:36:10 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39B0BuMs000640; Wed, 11 Oct 2023 00:36:08 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tkk5km88h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Oct 2023 00:36:08 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39B0a5KT23921294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 11 Oct 2023 00:36:05 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5622F20043; Wed, 11 Oct 2023 00:36:05 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73BDA20040; Wed, 11 Oct 2023 00:36:03 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 11 Oct 2023 00:36:03 +0000 (GMT) From: Jiufu Guo To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, richard.sandiford@arm.com, segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com, amacleod@redhat.com, aldyh@redhat.com Subject: [PATCH V1] use more get_range_query Date: Wed, 11 Oct 2023 08:36:02 +0800 Message-Id: <20231011003602.80416-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DRKGrThBL5veYHmPfV_rdgJOUzQVmhQa X-Proofpoint-ORIG-GUID: cYBIenswhdlY42ZF6uMI1SRm5LxU7qVE X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_19,2023-10-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 phishscore=0 impostorscore=0 clxscore=1015 adultscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=989 suspectscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310110003 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, For "get_global_range_query" SSA_NAME_RANGE_INFO can be queried. For "get_range_query", it could get more context-aware range info. And look at the implementation of "get_range_query", it returns global range if no local fun info. So, if not quering for SSA_NAME and not chaning the IL, it would be ok to use get_range_query to replace get_global_range_query. Patch https://gcc.gnu.org/pipermail/gcc-patches/2023-September/630389.html, Uses get_range_query could handle more cases. Compare with previous version: https://gcc.gnu.org/pipermail/gcc-patches/2023-October/632401.html This patch remove some unsafe replacement. Pass bootstrap & regtest on ppc64{,le} and x86_64. Is this ok for trunk. BR, Jeff (Jiufu Guo) gcc/ChangeLog: * fold-const.cc (expr_not_equal_to): Replace get_global_range_query by get_range_query. * gimple-fold.cc (size_must_be_zero_p): Likewise. * gimple-range-fold.cc (fur_source::fur_source): Likewise. * gimple-ssa-warn-access.cc (check_nul_terminated_array): Likewise. * tree-dfa.cc (get_ref_base_and_extent): Likewise. --- gcc/fold-const.cc | 6 +----- gcc/gimple-fold.cc | 6 ++---- gcc/gimple-range-fold.cc | 4 +--- gcc/gimple-ssa-warn-access.cc | 2 +- gcc/tree-dfa.cc | 5 +---- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 4f8561509ff..15134b21b9f 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -11056,11 +11056,7 @@ expr_not_equal_to (tree t, const wide_int &w) if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) return false; - if (cfun) - get_range_query (cfun)->range_of_expr (vr, t); - else - get_global_range_query ()->range_of_expr (vr, t); - + get_range_query (cfun)->range_of_expr (vr, t); if (!vr.undefined_p () && !vr.contains_p (w)) return true; /* If T has some known zero bits and W has any of those bits set, diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index dc89975270c..853edd9e5d4 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -876,10 +876,8 @@ size_must_be_zero_p (tree size) wide_int zero = wi::zero (TYPE_PRECISION (type)); value_range valid_range (type, zero, ssize_max); value_range vr; - if (cfun) - get_range_query (cfun)->range_of_expr (vr, size); - else - get_global_range_query ()->range_of_expr (vr, size); + get_range_query (cfun)->range_of_expr (vr, size); + if (vr.undefined_p ()) vr.set_varying (TREE_TYPE (size)); vr.intersect (valid_range); diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index d1945ccb554..6e9530c3d7f 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -50,10 +50,8 @@ fur_source::fur_source (range_query *q) { if (q) m_query = q; - else if (cfun) - m_query = get_range_query (cfun); else - m_query = get_global_range_query (); + m_query = get_range_query (cfun); m_gori = NULL; } diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index fcaff128d60..e439d1b9b68 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -332,7 +332,7 @@ check_nul_terminated_array (GimpleOrTree expr, tree src, tree bound) { Value_Range r (TREE_TYPE (bound)); - get_global_range_query ()->range_of_expr (r, bound); + get_range_query (cfun)->range_of_expr (r, bound); if (r.undefined_p () || r.varying_p ()) return true; diff --git a/gcc/tree-dfa.cc b/gcc/tree-dfa.cc index af8e9243947..5355af2c869 100644 --- a/gcc/tree-dfa.cc +++ b/gcc/tree-dfa.cc @@ -531,10 +531,7 @@ get_ref_base_and_extent (tree exp, poly_int64 *poffset, value_range vr; range_query *query; - if (cfun) - query = get_range_query (cfun); - else - query = get_global_range_query (); + query = get_range_query (cfun); if (TREE_CODE (index) == SSA_NAME && (low_bound = array_ref_low_bound (exp),