From patchwork Sat Sep 25 07:32:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 45432 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 0C0DC385840A for ; Sat, 25 Sep 2021 07:33:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 7066D3858403 for ; Sat, 25 Sep 2021 07:32:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7066D3858403 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kZmwBrMqRxy0pTl2MHj7huXl/MqGXMkoDXk+lRfTHxI=; b=hV5Ofx8fSqLqCZdJwWUy+Ambpk wtImBDaL8bdOD+3nLHcyHAoGGsDSpGjtK5rCfPDyZRpJJveWmXJi+wzSussTxPCp6pQtyEIirlPZw Ss2zXkoFrBHOtcWhsXkOd35TBloM/Qs+O8l0O6puBR6vdLgNErH/zRnipGbpYqGzzgEiG7/OET8sQ wUUuxd0vTUvqA3Z409zHlF4AbtggrGeM646+DlXS5acXGwMoW8NJtNlviJwvTZ+51Ray9QWQs6hMN LsY7WxOpIHwZE5zDrS1mrD497BkDEfJeu4htAsshPnQD1QU8sPvQW19EvDXhIPM1EKol3l+0eCFSk msEqA5hw==; Received: from host86-186-213-65.range86-186.btcentralplus.com ([86.186.213.65]:51784 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mU2B5-0000MV-OM; Sat, 25 Sep 2021 03:32:56 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Make flag_trapping_math a non-binary Boolean. Date: Sat, 25 Sep 2021 08:32:54 +0100 Message-ID: <01b201d7b1df$8eadd7e0$ac0987a0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adex3sT+8TlYQu6/QuWKuSb7481SWg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: 'Eric Botcazou' Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Normally Boolean options/flags in GCC take the values zero or one. This patch tweaks flag_trapping_math to take the values 0 or 65535. More accurately it introduces a new trapping_math_model enumeration in flag-types.h, and uses this to allow front-ends to (potentially) control which expressions may be constant folded at compile-time by the middle-end. Floating point/language experts may recognize these flags (bits) as being modelled upon (extended) FENV_ACCESS. This instalment simply introduces the necessary infrastructure without yet changing any functionality. The test "if (flag_trapping_math)" will remain perfectly valid (but pessimistic). The goal is to allow time for out-of-tree front-ends (modula-2, rust, etc.) to update themselves, if required, and to confirm that this change doesn't introduce problems for LTO, or elsewhere. This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap" and "make -k check", all languages including Ada, with no new failures. Ok for mainline? 2021-09-25 Roger Sayle gcc/ChangeLog * flag-types.h (trapping_math_model): New enumeration (of bits) specifying possible floating-point (and integer) exceptions/traps. * common.opt (ftrapping-math): Specify UInteger and initialize to flag_trapping_math to TRAPPING_MATH_DEFAULT. * toplev.c (process_options): The option -fsignaling-nans should set flag_trapping_math to TRAPPING_MATH_DEFAULT. gcc/ada/ChangeLog * gcc-interface/misc.c (gnat_init_gcc_fp): Set flag_trapping_math to TRAPPING_MATH_DEFAULT (instead of 1) if S'Machine_Overflow. Roger diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index 96199bd..93cbc71 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -451,7 +451,7 @@ gnat_init_gcc_fp (void) /* Assume that FP operations can trap if S'Machine_Overflow is true, but don't override the user if not. */ if (Machine_Overflows_On_Target) - flag_trapping_math = 1; + flag_trapping_math = TRAPPING_MATH_DEFAULT; else if (!global_options_set.x_flag_trapping_math) flag_trapping_math = 0; } diff --git a/gcc/common.opt b/gcc/common.opt index b921f5e..314f9a7 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2750,7 +2750,7 @@ generate them instead of using descriptors. ; (user-visible) trap. This is the case, for example, in nonstop ; IEEE 754 arithmetic. ftrapping-math -Common Var(flag_trapping_math) Init(1) Optimization SetByCombined +Common Var(flag_trapping_math) Init(TRAPPING_MATH_DEFAULT) Optimization SetByCombined UInteger Assume floating-point operations can trap. ftrapv diff --git a/gcc/flag-types.h b/gcc/flag-types.h index 5bd1f77..98b9ff0 100644 --- a/gcc/flag-types.h +++ b/gcc/flag-types.h @@ -481,6 +481,33 @@ enum openacc_privatization OPENACC_PRIVATIZATION_NOISY }; +/* Trapping math exception classes. */ +enum trapping_math_model +{ + TRAPPING_MATH_NONE = 0, + TRAPPING_MATH_QNANOP = 1UL << 0, + TRAPPING_MATH_SNANOP = 1UL << 1, + TRAPPING_MATH_QNANCMP = 1UL << 2, + TRAPPING_MATH_SNANCMP = 1UL << 3, + TRAPPING_MATH_INTCONV = 1UL << 4, + TRAPPING_MATH_SQRTNEG = 1UL << 5, + TRAPPING_MATH_LIBMFUN = 1UL << 6, + TRAPPING_MATH_FDIVZERO = 1UL << 7, + TRAPPING_MATH_IDIVZERO = 1UL << 8, + TRAPPING_MATH_FPDENORM = 1UL << 9, + TRAPPING_MATH_OVERFLOW = 1UL << 10, + TRAPPING_MATH_UNDERFLOW = 1UL << 11, + TRAPPING_MATH_INFDIVINF = 1UL << 12, + TRAPPING_MATH_INFSUBINF = 1UL << 13, + TRAPPING_MATH_INFMULZERO = 1UL << 14, + TRAPPING_MATH_ZERODIVZERO = 1UL << 15, + + TRAPPING_MATH_DEFAULT = (1UL << 16) - 1, + + TRAPPING_MATH_INEXACT = 1UL << 16, + TRAPPING_MATH_TRAPV = 1UL << 17 +}; + #endif #endif /* ! GCC_FLAG_TYPES_H */ diff --git a/gcc/toplev.c b/gcc/toplev.c index 14d1335..6cd71cc 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1664,7 +1664,7 @@ process_options (void) /* The presence of IEEE signaling NaNs, implies all math can trap. */ if (flag_signaling_nans) - flag_trapping_math = 1; + flag_trapping_math = TRAPPING_MATH_DEFAULT; /* We cannot reassociate if we want traps or signed zeros. */ if (flag_associative_math && (flag_trapping_math || flag_signed_zeros))