From patchwork Fri Sep 15 01:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1834549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nPnkIMJs; 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 4RmxhW6px3z1yhd for ; Fri, 15 Sep 2023 11:40:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EFFF23858C33 for ; Fri, 15 Sep 2023 01:40:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFFF23858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694742004; bh=RwcQ8ZXybkMydHN8cZBW1AeU3VHy6fM07Ba85HCcSFk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=nPnkIMJsjiQNO/eP8jWWee6IDHohWhzBvsgmNZ2Q049ojttBE06wVAbNjz1b/mz6B O9kwKl+yKhVZqEXIpevRq4RDrWJN0Gx0i2ouUh2n8vbwHChdpbB0Hb/iIsLZsic01d 1HxR0ZGUa0EIj8/Z+lELOgAWqhhJ7j1Vt/P+vvS4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id AF1F13858C52; Fri, 15 Sep 2023 01:39:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF1F13858C52 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38F1coO7010469; Fri, 15 Sep 2023 01:39:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t4djng5t1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Sep 2023 01:39:28 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 38F1dOGk012611; Fri, 15 Sep 2023 01:39:28 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t4djng5sh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Sep 2023 01:39:28 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38ENxtuW023099; Fri, 15 Sep 2023 01:39:27 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3t141p776k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Sep 2023 01:39:26 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38F1dNBZ62783782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Sep 2023 01:39:23 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA7FC2004B; Fri, 15 Sep 2023 01:39:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCF8D20049; Fri, 15 Sep 2023 01:39:21 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 15 Sep 2023 01:39:21 +0000 (GMT) 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] use local range for one more pattern in match.pd Date: Fri, 15 Sep 2023 09:39:21 +0800 Message-Id: <20230915013921.1868899-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FxCb5az9mEyImYjntJLymWyv-VzY9UIl X-Proofpoint-ORIG-GUID: ttNXnA6t1ouk7aiy9HcbXL7lbsVurDFD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_02,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 priorityscore=1501 malwarescore=0 spamscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=900 bulkscore=0 suspectscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309150012 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, 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: , X-Patchwork-Original-From: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. ATTRIBUTE_RETURNS_NONNULL inline range_query * get_range_query (const struct function *fun) { return (fun && fun->x_range_query) ? fun->x_range_query : &global_ranges; } So, using "get_range_query" would cover more case. For example, the test case of "pr111303.c". Bootstrap ®test pass on ppc64{,le} and x86_64. Is this ok for trunk? BR, Jeff (Jiufu Guo) PR middle-end/111303 gcc/ChangeLog: * match.pd ((t * 2) / 2): Update pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr111303.c: New test. --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.dg/tree-ssa/pr111303.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr111303.c diff --git a/gcc/match.pd b/gcc/match.pd index 693638f8ca0..6bd72ff4d69 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -931,8 +931,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) bool overflowed = true; value_range vr0, vr1; if (INTEGRAL_TYPE_P (type) - && get_global_range_query ()->range_of_expr (vr0, @0) - && get_global_range_query ()->range_of_expr (vr1, @1) + && get_range_query (cfun)->range_of_expr (vr0, @0) + && get_range_query (cfun)->range_of_expr (vr1, @1) && !vr0.varying_p () && !vr0.undefined_p () && !vr1.varying_p () && !vr1.undefined_p ()) { diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c new file mode 100644 index 00000000000..b703fe4546d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111303.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +typedef unsigned int INT; + +INT +foo (INT x, INT y) +{ + if (x > 100 || y > 100) + return x; + return (x * y) / y; +} + +/* { dg-final { scan-tree-dump-times "return x_..D." 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times " / " 0 "optimized"} } */