From patchwork Fri Aug 16 09:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 1973178 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=Le4k3ZvK; 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 4Wlcby5Dwbz1yfB for ; Fri, 16 Aug 2024 19:47:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BB02385AC29 for ; Fri, 16 Aug 2024 09:47:40 +0000 (GMT) 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 97B0E385DDC6 for ; Fri, 16 Aug 2024 09:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97B0E385DDC6 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97B0E385DDC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723801639; cv=none; b=mzfHdIp1LP9I5J27AmUsr++stZHRMoDm+EpMgRt9iJ6Zb3ArdxhynOTwhhkYXiDiyMj7nyfmbpSzVJlldoAy+N192IO7CL8rPmHk/Msem0MbRCeL37miShbGZe9UhPz4InrNGWH+N+DGO1+7qM7LkkadFIwew6j4tX0EY7wWkAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723801639; c=relaxed/simple; bh=Pkw+eMpLPMona/0Gld3kj6HyC5kVXbwEZdthVkve1HU=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=F+Z/R5U/O2lOw+zxhXh17RtcZgI2EwBWM9qY4uEE69D7yS7ZRcOEh0oRHv7lsWosgBSp2TDz+YvLMTfE6jHyFQS5BWIMvQngb8jo4U8cwKnb8o13hGp+ILXNSAQbJHw8P4kbi69VIM4Tn8nBBy//kH7PFzSIqIo48CJOOnhjTeU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47FKXgDb001439; Fri, 16 Aug 2024 09:47:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:to:cc:from:subject:content-type :content-transfer-encoding:mime-version; s=pp1; bh=bSNjFhuKIl6FX sT7PS7hPw3vAjSSbtVzMUM6ncnDr78=; b=Le4k3ZvK+CsnFha/DtBv+QzScW/AJ vXo0VYSdOO0QH51/Ei9prTeyzyjTqz9//UpHrekr/FnrypQl4ijlvDENqTtd8FCK 2xecSf3eLji0oRuPZ+yiHvfDMUcmAZpAJMJPgC+HxTN09RzayrnXD2wCRauLxlTb CzU27qqmRFx27MV0QtaotX9x3jJ8nvgMxBs6wFiMrJS1BASjZXq3hxE55Mbf+ulw LuM9vBg49He5W4HLwx4BQnXl/M0EsyeCPPqeuiNYj1H0ENBDBFzEC35yznv6h9Xy frEboix2uuss4qjjyBkcfFgq32GHW4L/Fu7RTMBGDa0CdFLoAMqWY/bAA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4111j5yuw7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Aug 2024 09:47:16 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 47G9gAXB012700; Fri, 16 Aug 2024 09:47:15 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4111j5yuw4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Aug 2024 09:47:15 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 47G8NNgN029932; Fri, 16 Aug 2024 09:47:14 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 40xmrmtsu2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Aug 2024 09:47:14 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 47G9l9tE46989610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Aug 2024 09:47:11 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFDE320043; Fri, 16 Aug 2024 09:47:08 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D515620040; Fri, 16 Aug 2024 09:47:06 +0000 (GMT) Received: from [9.197.240.242] (unknown [9.197.240.242]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 16 Aug 2024 09:47:06 +0000 (GMT) Message-ID: <3ad56ccc-0787-4035-b85e-002390748f64@linux.ibm.com> Date: Fri, 16 Aug 2024 17:47:04 +0800 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Richard Biener From: HAO CHEN GUI Subject: [PATCH-2] Builtins: Fold isfinite on IBM long double to isfinite on high-order double [PR97786] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: aMvMkgIANUlZfstm9hesVhB3QIAuTUd1 X-Proofpoint-GUID: V5IDO-thHPS9z7H6l26MYPRDVqfWYz0J X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-16_01,2024-08-15_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 mlxlogscore=581 bulkscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408160069 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.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, This patch folds builtin_isfinite on IBM long double to builtin_isfinite on its high-order double. The isfinite_optab was already implemented in this patch. https://gcc.gnu.org/g:44eb45c2ef7192eb6a811fd46fcb2c7fbeb6f865 Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Is it OK for the trunk? Thanks Gui Haochen ChangeLog Builtins: Fold isfinite on IBM long double to isfinite on high-order double For IBM long double, INF and NAN is encoded in the high-order double value only. So the builtin_isfinite on IBM long double can be folded to builtin_isfinite on double type. As former patch implemented DFmode isfinite_optab, this patch converts builtin_isfinite on IBM long double to builtin_isfinite on double type if the DFmode isfinite_optab exists. gcc/ PR target/97786 * builtins.cc (fold_builtin_interclass_mathfn): Fold isfinite on IBM long double to isfinite on high-order double when DFmode isfinite_optab exists. gcc/testsuite/ PR target/97786 * gcc.target/powerpc/pr97786-6.c: New test. patch.diff diff --git a/gcc/builtins.cc b/gcc/builtins.cc index c20bd7b5f31..c3d8ce5313a 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -9601,6 +9601,15 @@ fold_builtin_interclass_mathfn (location_t loc, tree fndecl, tree arg) type = double_type_node; mode = DFmode; arg = fold_build1_loc (loc, NOP_EXPR, type, arg); + + /* If isfinite icode exists, build the call with high-order + double value only. */ + tree const isfinite_fn = builtin_decl_explicit (BUILT_IN_ISFINITE); + if (interclass_mathfn_icode (arg, isfinite_fn) != CODE_FOR_nothing) + { + result = build_call_expr (isfinite_fn, 1, arg); + return result; + } } get_max_float (REAL_MODE_FORMAT (mode), buf, sizeof (buf), false); real_from_string (&r, buf); diff --git a/gcc/testsuite/gcc.target/powerpc/pr97786-6.c b/gcc/testsuite/gcc.target/powerpc/pr97786-6.c new file mode 100644 index 00000000000..1b25bcecd5a --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr97786-6.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ppc_float128_hw } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -mvsx -mabi=ibmlongdouble -Wno-psabi" } */ +/* { dg-require-effective-target powerpc_vsx } */ + +int test1 (long double x) +{ + return __builtin_isfinite (x); +} + +/* { dg-final { scan-assembler-not {\mfcmpu\M} } } */ +/* { dg-final { scan-assembler {\mxststdcdp\M} } } */