From patchwork Mon Dec 19 08:11:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 62127 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 707323A2A905 for ; Mon, 19 Dec 2022 08:29:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 707323A2A905 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671438572; bh=h9untzJb3xJZ4aH4kcqYb00P3yd+U8wquyxteGvhrow=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dQlBSOGH/IUc3P5MtxAsVPauCoW36FO3sSL+cxtZkJH42/Jc0ygnv40I/4f9BhikH 8Nrrd2J+UkdkySvRaXjVZZ+GquLX9Wy8qCtnB4cccQdzS10CvrzAlN5bOTHzVR0j4F zYS1Tid1M3ovfKnmG8DBUZbmGtPX8xa0EMeOPjGI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 052AC3D9F31B for ; Mon, 19 Dec 2022 08:12:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 052AC3D9F31B Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJ7jreS021934; Mon, 19 Dec 2022 08:12:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mjkuurt8m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 08:12:10 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2BJ7kA9r022543; Mon, 19 Dec 2022 08:12:09 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mjkuurt6r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 08:12:09 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 2BJ2O5K7025317; Mon, 19 Dec 2022 08:12:07 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3mh6ywj2wm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 19 Dec 2022 08:12:07 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2BJ8C3NF35586452 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Dec 2022 08:12:04 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 673952004B; Mon, 19 Dec 2022 08:12:03 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E95B720040; Mon, 19 Dec 2022 08:12:00 +0000 (GMT) Received: from [9.197.234.5] (unknown [9.197.234.5]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 19 Dec 2022 08:12:00 +0000 (GMT) Message-ID: Date: Mon, 19 Dec 2022 16:11:59 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US Subject: [PATCH] fold-const: Treat fp conversion to a type with same mode as copy To: GCC Patches Cc: Richard Biener , Segher Boessenkool , Jakub Jelinek , Joseph Myers , Michael Meissner X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: YhOqTd7VoU4OlNXYWNwKvzQ58MymOPN4 X-Proofpoint-GUID: 8q0llqZ5EIMME9mXLoxL97r1RUbR_PpH X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-18_13,2022-12-15_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 suspectscore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212190070 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, In function fold_convert_const_real_from_real, when the modes of two types involved in fp conversion are the same, we can simply take it as copy, rebuild with the exactly same TREE_REAL_CST and the target type. It is more efficient and helps to avoid possible unexpected signalling bit clearing in [1]. Bootstrapped and regtested on x86_64-redhat-linux, aarch64-linux-gnu and powerpc64{,le}-linux-gnu. Is it ok for trunk? [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608533.html gcc/ChangeLog: * fold-const.cc (fold_convert_const_real_from_real): Treat floating point conversion to a type with same mode as copy instead of normal convertFormat. --- gcc/fold-const.cc | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.27.0 diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 114258fa182..eb4b6ca8820 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -2178,6 +2178,15 @@ fold_convert_const_real_from_real (tree type, const_tree arg1) REAL_VALUE_TYPE value; tree t; + /* If the underlying modes are the same, simply treat it as + copy and rebuild with TREE_REAL_CST information and the + given type. */ + if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (arg1))) + { + t = build_real (type, TREE_REAL_CST (arg1)); + return t; + } + /* Don't perform the operation if flag_signaling_nans is on and the operand is a signaling NaN. */ if (HONOR_SNANS (arg1)