From patchwork Mon Aug 15 10:20:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1274646pxh; Mon, 15 Aug 2022 03:21:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR7c5DaGG0fxpw2wvqrTxk8LEJ/u0w3X2jiC9ap9ZGjfXf6Vb2vB/Q31B9TWcE2MthexO2CJ X-Received: by 2002:a17:906:84ef:b0:730:ba33:512b with SMTP id zp15-20020a17090684ef00b00730ba33512bmr10138388ejb.346.1660558897314; Mon, 15 Aug 2022 03:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660558897; cv=none; d=google.com; s=arc-20160816; b=D9eNPwm3+a97vDJw6I4cid7/O8gWWzGtbdhxQ2rFtN3pWXcCMFv/aA0/ZjIVS4HyuU q1lzm4WWFGoi9kYLUjCU+9+AI72oKfnCQYzUDcvZzQ0UmGJLKo703ZBJ8uXaO0ib+V6O XR97hOVpujTp5ThPiQW8c1nVHalO4B4UGlZ0G5ca9ZqxO9hPjrJfPkTtNYKiBjuPXOSQ HG/1zzWYaIZ1SleuJYxD7QEIjhWXZqhN6taTggElT03RfzpsuoXGCgEcXqzsx6qDjetE 0Pf25rWf+Fu6gyMYoKTrS2P5hfvfGfVhlmsFAy57zuxq/W/r51J7T37smM5zzINWwojS Mr9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iiMp1AuNuEJMbfB3/GGZcy4hRmMjeDPZ3XAzRejbYoY=; b=uzJDPBxKqcEcPYbg0+szkEoqvxpCPKCf4baDcUDq3/0UPsPmCsBtDwmwBDiweBDgf7 ACZalM4YYSXfqXn6swW1lk5lXn+M2uqWoX+Naca/uRdJ9Gbp7Y0vfbTJrfmEfloh1jM0 gIrxZ+2NpYRVIbEwH6MmDQhp0mjharKQT246xOkX4a/iADM6Qoda3wKBNPWv744oJKaW LdfxdOAYiEA/fa5usPg1XK2sbNAb7jgEfQXcnuXLu6Q9X1CLnaMeEjPkksdY4apO3QBh yjr3bKp24xbCKG0akbeHdObGpTOtAmv+THdpNL0pDJBQm0f+GkD5NdvP11l0IwTARR8O TSIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UuCyQLRF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qw40-20020a1709066a2800b00732fca94958si7941182ejc.706.2022.08.15.03.21.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Aug 2022 03:21:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UuCyQLRF; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D1AB53857C4D for ; Mon, 15 Aug 2022 10:21:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1AB53857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660558895; bh=iiMp1AuNuEJMbfB3/GGZcy4hRmMjeDPZ3XAzRejbYoY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=UuCyQLRFwGEtZpfv47Vid8MspMKCUxQzKG+ORWlp1p9g2ZgGh/BquhybghTTdX09s EyoY116PbOnQ++T2eg9MGhE+IOLKuuxEaEMhzxfVglgUTaIs1YE83LXLwKxt2Ifhm+ PBmwGqCKJIer+Kj51DRlV4xg5jBTffTxSuifQvIM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A50133857C49 for ; Mon, 15 Aug 2022 10:20:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A50133857C49 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-OfC_z76pPkKeqyMKlICq6Q-1; Mon, 15 Aug 2022 06:20:49 -0400 X-MC-Unique: OfC_z76pPkKeqyMKlICq6Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2AE46A0CA66; Mon, 15 Aug 2022 10:20:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFFDE492CA2; Mon, 15 Aug 2022 10:20:48 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 27FAKkAc1240910 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 Aug 2022 12:20:46 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 27FAKj9B1240909; Mon, 15 Aug 2022 12:20:45 +0200 Date: Mon, 15 Aug 2022 12:20:45 +0200 To: FX Subject: [PATCH] fortran: Expand ieee_arithmetic module's ieee_value inline [PR106579] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741222206201068833?= X-GMAIL-MSGID: =?utf-8?q?1741222206201068833?= Hi! The following patch expands IEEE_VALUE function inline in the FE. Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux and powerpc64-linux, ok for trunk? 2022-08-15 Jakub Jelinek PR fortran/106579 * trans-intrinsic.cc: Include realmpfr.h. (conv_intrinsic_ieee_value): New function. (gfc_conv_ieee_arithmetic_function): Handle ieee_value. Jakub --- gcc/fortran/trans-intrinsic.cc.jj 2022-08-12 18:51:28.095927643 +0200 +++ gcc/fortran/trans-intrinsic.cc 2022-08-13 13:24:37.446768877 +0200 @@ -41,6 +41,7 @@ along with GCC; see the file COPYING3. #include "trans-array.h" #include "dependency.h" /* For CAF array alias analysis. */ #include "attribs.h" +#include "realmpfr.h" /* Only for gfc_trans_assign and gfc_trans_pointer_assign. */ @@ -10085,6 +10086,115 @@ conv_intrinsic_ieee_class (gfc_se *se, g } +/* Generate code for IEEE_VALUE. */ + +static void +conv_intrinsic_ieee_value (gfc_se *se, gfc_expr *expr) +{ + tree args[2], arg, ret, tmp; + stmtblock_t body; + + /* Convert args, evaluate the second one only once. */ + conv_ieee_function_args (se, expr, args, 2); + arg = gfc_evaluate_now (args[1], &se->pre); + + tree type = TREE_TYPE (arg); + gcc_assert (TREE_CODE (type) == RECORD_TYPE); + tree field = NULL_TREE; + for (tree f = TYPE_FIELDS (type); f != NULL_TREE; f = DECL_CHAIN (f)) + if (TREE_CODE (f) == FIELD_DECL) + { + gcc_assert (field == NULL_TREE); + field = f; + } + gcc_assert (field); + arg = fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (field), + arg, field, NULL_TREE); + arg = gfc_evaluate_now (arg, &se->pre); + + type = gfc_typenode_for_spec (&expr->ts); + gcc_assert (TREE_CODE (type) == REAL_TYPE); + ret = gfc_create_var (type, NULL); + + gfc_init_block (&body); + + tree end_label = gfc_build_label_decl (NULL_TREE); + for (int c = IEEE_SIGNALING_NAN; c <= IEEE_POSITIVE_INF; ++c) + { + tree label = gfc_build_label_decl (NULL_TREE); + tree low = build_int_cst (TREE_TYPE (arg), c); + tmp = build_case_label (low, low, label); + gfc_add_expr_to_block (&body, tmp); + + REAL_VALUE_TYPE real; + int k; + switch (c) + { + case IEEE_SIGNALING_NAN: + real_nan (&real, "", 0, TYPE_MODE (type)); + break; + case IEEE_QUIET_NAN: + real_nan (&real, "", 1, TYPE_MODE (type)); + break; + case IEEE_NEGATIVE_INF: + real_inf (&real); + real = real_value_negate (&real); + break; + case IEEE_NEGATIVE_NORMAL: + real_from_integer (&real, TYPE_MODE (type), -42, SIGNED); + break; + case IEEE_NEGATIVE_DENORMAL: + k = gfc_validate_kind (BT_REAL, expr->ts.kind, false); + real_from_mpfr (&real, gfc_real_kinds[k].tiny, + type, GFC_RND_MODE); + real_arithmetic (&real, RDIV_EXPR, &real, &dconst2); + real = real_value_negate (&real); + break; + case IEEE_NEGATIVE_ZERO: + real_from_integer (&real, TYPE_MODE (type), 0, SIGNED); + real = real_value_negate (&real); + break; + case IEEE_POSITIVE_ZERO: + /* Make this also the default: label. */ + label = gfc_build_label_decl (NULL_TREE); + tmp = build_case_label (NULL_TREE, NULL_TREE, label); + gfc_add_expr_to_block (&body, tmp); + real_from_integer (&real, TYPE_MODE (type), 0, SIGNED); + break; + case IEEE_POSITIVE_DENORMAL: + k = gfc_validate_kind (BT_REAL, expr->ts.kind, false); + real_from_mpfr (&real, gfc_real_kinds[k].tiny, + type, GFC_RND_MODE); + real_arithmetic (&real, RDIV_EXPR, &real, &dconst2); + break; + case IEEE_POSITIVE_NORMAL: + real_from_integer (&real, TYPE_MODE (type), 42, SIGNED); + break; + case IEEE_POSITIVE_INF: + real_inf (&real); + break; + default: + gcc_unreachable (); + } + + tree val = build_real (type, real); + gfc_add_modify (&body, ret, val); + + tmp = build1_v (GOTO_EXPR, end_label); + gfc_add_expr_to_block (&body, tmp); + } + + tmp = gfc_finish_block (&body); + tmp = fold_build2_loc (input_location, SWITCH_EXPR, NULL_TREE, arg, tmp); + gfc_add_expr_to_block (&se->pre, tmp); + + tmp = build1_v (LABEL_EXPR, end_label); + gfc_add_expr_to_block (&se->pre, tmp); + + se->expr = ret; +} + + /* Generate code for an intrinsic function from the IEEE_ARITHMETIC module. */ @@ -10117,6 +10227,8 @@ gfc_conv_ieee_arithmetic_function (gfc_s conv_intrinsic_ieee_logb_rint (se, expr, BUILT_IN_RINT); else if (startswith (name, "ieee_class_") && ISDIGIT (name[11])) conv_intrinsic_ieee_class (se, expr); + else if (startswith (name, "ieee_value_") && ISDIGIT (name[11])) + conv_intrinsic_ieee_value (se, expr); else /* It is not among the functions we translate directly. We return false, so a library function call is emitted. */