From patchwork Tue May 21 02:52:14 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: 1937197 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=I5cG/QPy; 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 4VjzWS1jvZz20KF for ; Tue, 21 May 2024 12:52:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8162A3858416 for ; Tue, 21 May 2024 02:52:50 +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 74FD43858C62 for ; Tue, 21 May 2024 02:52:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74FD43858C62 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 74FD43858C62 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=1716259950; cv=none; b=bAE+5mAJQaHRmWsXUqSzGrLwAA/hzBhxJeIHpcGM3XDb88Xuyj/NydC+ju7Q7KRBNnNROmK5kLOMpvznUXDP+fevrhn3VlR2H8mPUUgKTZM3NKb3xtQGpOI4p0nR72LPZFpVJe20bQ3UK57CgDLSkAQj0OHaRJzFMVc3r3g4k+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716259950; c=relaxed/simple; bh=7/S3l5F+H8amzMnESxy/dRxFZ8r5YpEx8qG7qu61ZwE=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=CGAzJftoU9NiVtiUVh/GAK4Vp+TwzGYkph9ntgbD4ul1ilZIYK1EuC7K+6d0XyBtZoUdCKyHDz+EavK0QyR6/2nCYFm0J0y/3d0MDUrIKq8xcAjEnbl11CvOyKldDfTDI1Wvy/iVMmN6+v9ipbaJSKgeB8LzhX/2EbNEx3ijL3E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44L17bou013911; Tue, 21 May 2024 02:52:25 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=k9kFILkJ8DAwHTS2nmqw7vzb5kJuHjEG9neDRYnftfQ=; b=I5cG/QPydxuT8Nt0RcZOXxO+2LM70R0CKmplITMeAo6A5RjmZJfo/S6/CjNyTm/r8aDJ 1rfyt89Qf4MuKPbj5s+yc+tgnJTkgXvtfbFvUjNpG/brOPgNNDtpCom9O4ze+mtOlPtN iAxLTW8YPzF0Qd1TE1qQawuaUQE/g/d3aYDu8hLJZYEcbVhleN0xuy/x4v1vKtw8Pu2E p6FX8tX/d8P/iXtevs37BEhnokCfYzW/njOt0gdDxQgpEc8OtYXJ6vO54eeEEdiSSvPB EhVTY66qfUkE1fCqtaJzKELHyeinAp5UWHrEntvimwqGgevmpRlzrQsxtzQbBhu2kfyr 7w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3y8hnt8668-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 02:52:25 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44L2qOiF014471; Tue, 21 May 2024 02:52:24 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 3y8hnt8664-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 02:52:24 +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 44L0EfxO026453; Tue, 21 May 2024 02:52:23 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3y785mb5nv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 May 2024 02:52:23 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 44L2qHbk51052952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 May 2024 02:52:19 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D11120043; Tue, 21 May 2024 02:52:17 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B250120040; Tue, 21 May 2024 02:52:14 +0000 (GMT) Received: from [9.200.103.244] (unknown [9.200.103.244]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 May 2024 02:52:14 +0000 (GMT) Message-ID: <49b03b9a-9a0c-44e3-9134-b01ebc758167@linux.ibm.com> Date: Tue, 21 May 2024 10:52:14 +0800 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Mikael Morin , "MacLeod, Andrew" , Aldy Hernandez , Jakub Jelinek From: HAO CHEN GUI Subject: [PATCH-1v2] Value Range: Add range op for builtin isinf X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _J8wUWMoMW8dFS3T3YLLek_I7Ozr7e7Z X-Proofpoint-GUID: w8ZTmS7F72D_fM70d7TjJRoHf-j2gA-h 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.650,FMLib:17.12.28.16 definitions=2024-05-21_02,2024-05-17_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 adultscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405210022 X-Spam-Status: No, score=-12.4 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, The builtin isinf is not folded at front end if the corresponding optab exists. It causes the range evaluation failed on the targets which has optab_isinf. For instance, range-sincos.c will fail on the targets which has optab_isinf as it calls builtin_isinf. This patch fixed the problem by adding range op for builtin isinf. Compared with previous version, the main change is to set varying if nothing is known about the range. https://gcc.gnu.org/pipermail/gcc-patches/2024-March/648303.html Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no regressions. Is it OK for the trunk? Thanks Gui Haochen ChangeLog Value Range: Add range op for builtin isinf The builtin isinf is not folded at front end if the corresponding optab exists. So the range op for isinf is needed for value range analysis. This patch adds range op for builtin isinf. gcc/ * gimple-range-op.cc (class cfn_isinf): New. (op_cfn_isinf): New variables. (gimple_range_op_handler::maybe_builtin_call): Handle CASE_FLT_FN (BUILT_IN_ISINF). gcc/testsuite/ * gcc/testsuite/gcc.dg/tree-ssa/range-isinf.c: New test. patch.diff diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 55dfbb23ce2..eb1b0aff77c 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -1175,6 +1175,62 @@ private: bool m_is_pos; } op_cfn_goacc_dim_size (false), op_cfn_goacc_dim_pos (true); +// Implement range operator for CFN_BUILT_IN_ISINF +class cfn_isinf : public range_operator +{ +public: + using range_operator::fold_range; + using range_operator::op1_range; + virtual bool fold_range (irange &r, tree type, const frange &op1, + const irange &, relation_trio) const override + { + if (op1.undefined_p ()) + return false; + + if (op1.known_isinf ()) + { + r.set_nonzero (type); + return true; + } + + if (op1.known_isnan () + || (!real_isinf (&op1.lower_bound ()) + && !real_isinf (&op1.upper_bound ()))) + { + r.set_zero (type); + return true; + } + + r.set_varying (type); + return true; + } + virtual bool op1_range (frange &r, tree type, const irange &lhs, + const frange &, relation_trio) const override + { + if (lhs.undefined_p ()) + return false; + + if (lhs.zero_p ()) + { + nan_state nan (true); + r.set (type, real_min_representable (type), + real_max_representable (type), nan); + return true; + } + + if (!range_includes_zero_p (lhs)) + { + // The range is [-INF,-INF][+INF,+INF], but it can't be represented. + // Set range to [-INF,+INF] + r.set_varying (type); + r.clear_nan (); + return true; + } + + r.set_varying (type); + return true; + } +} op_cfn_isinf; // Implement range operator for CFN_BUILT_IN_ class cfn_parity : public range_operator @@ -1268,6 +1324,11 @@ gimple_range_op_handler::maybe_builtin_call () m_operator = &op_cfn_signbit; break; + CASE_FLT_FN (BUILT_IN_ISINF): + m_op1 = gimple_call_arg (call, 0); + m_operator = &op_cfn_isinf; + break; + CASE_CFN_COPYSIGN_ALL: m_op1 = gimple_call_arg (call, 0); m_op2 = gimple_call_arg (call, 1); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/range-isinf.c b/gcc/testsuite/gcc.dg/tree-ssa/range-isinf.c new file mode 100644 index 00000000000..468f1bcf5c7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/range-isinf.c @@ -0,0 +1,44 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp" } */ + +#include +void link_error(); + +void +test1 (double x) +{ + if (x > __DBL_MAX__ && !__builtin_isinf (x)) + link_error (); + if (x < -__DBL_MAX__ && !__builtin_isinf (x)) + link_error (); +} + +void +test2 (float x) +{ + if (x > __FLT_MAX__ && !__builtin_isinf (x)) + link_error (); + if (x < -__FLT_MAX__ && !__builtin_isinf (x)) + link_error (); +} + +void +test3 (double x) +{ + if (!__builtin_isinf (x) && !__builtin_isnan (x) && x > __DBL_MAX__) + link_error (); + if (!__builtin_isinf (x) && !__builtin_isnan (x) && x < -__DBL_MAX__) + link_error (); +} + +void +test4 (float x) +{ + if (!__builtin_isinf (x) && !__builtin_isnan (x) && x > __FLT_MAX__) + link_error (); + if (!__builtin_isinf (x) && !__builtin_isnan (x) && x < -__FLT_MAX__) + link_error (); +} + +/* { dg-final { scan-tree-dump-not "link_error" "evrp" } } */ +