From patchwork Fri Jan 31 17:00:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 1232047 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518656-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=de.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=OFEo12xs; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 488Nlj4pn6z9sPJ for ; Sat, 1 Feb 2020 04:01:05 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:date:from:cc:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=Thnp2 G28FXv8LD57lagmFn6zAn/F0/WcLonqvWHE522OPMDsQYoCgywYjyM7zkNiM8G9Q 1lMNhYcr4Av7boXlPDsgzozFIi0bEwSO8r0Trzs/N8bJB32ER1WdsMucXEjTnzGS aY4n/qYYBPeDrAGE3bcw5UnUbaJ5kIUU+jfCzE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:date:from:cc:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=xX8FMtk6OD0 /sScq8D4kyGWAric=; b=OFEo12xsv4lK5n06hjzPUeYGyWmx8+pgi3FrmDSj+VQ wMIVT00R49RKhjlqPG5SETsT6aTBpeFh7xfpW18gtsLi18iLEHszys7EaO0NVM7e XYPU71c7Lmz9kQQE+XVu8+GAutc1Fcg/zzshkSuvXy7FajClEBSN+Z3blegSkwRY = Received: (qmail 22641 invoked by alias); 31 Jan 2020 17:00:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 22590 invoked by uid 89); 31 Jan 2020 17:00:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:fassoci X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 Jan 2020 17:00:54 +0000 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00VH0ktM003902 for ; Fri, 31 Jan 2020 12:00:52 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 2xvq5m2n8b-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 31 Jan 2020 12:00:51 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 31 Jan 2020 17:00:34 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 31 Jan 2020 17:00:31 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 00VH0UXN60096592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 Jan 2020 17:00:30 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C72E4C040; Fri, 31 Jan 2020 17:00:30 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 559034C050; Fri, 31 Jan 2020 17:00:30 +0000 (GMT) Received: from oc3748833570.ibm.com (unknown [9.152.214.23]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 31 Jan 2020 17:00:30 +0000 (GMT) Received: by oc3748833570.ibm.com (Postfix, from userid 1000) id 206D5D80316; Fri, 31 Jan 2020 18:00:30 +0100 (CET) Subject: [PATCH] Fix -ffast-math flags handling inconsistencies To: gcc-patches@gcc.gnu.org Date: Fri, 31 Jan 2020 18:00:30 +0100 (CET) From: "Ulrich Weigand" Cc: joseph@codesourcery.com MIME-Version: 1.0 x-cbid: 20013117-4275-0000-0000-0000039CD780 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20013117-4276-0000-0000-000038B0F8DC Message-Id: <20200131170030.206D5D80316@oc3748833570.ibm.com> Hello, we've noticed some inconsistencies in how the component flags of -ffast-math are handled, see the discussion on the GCC list starting here: https://gcc.gnu.org/ml/gcc/2020-01/msg00365.html This patch fixes those inconsistencies. Specifically, there are the following changes: 1. Some component flags for -ffast-math are *set* with -ffast-math (changing the default), but are not reset with -fno-fast-math, causing the latter to have surprising results. (Note that since "-ffast-math -fno-fast-math" is short-cut by the driver, you'll only see the surprising results with "-Ofast -fno-fast-math".) This is fixed here by both setting and resetting the flags. This affects the following flags -fcx-limited-range -fexcess-precision= 2. Some component flags for -ffast-math are changed from their default, but are *not* included in the fast_math_flags_set_p test, causing __FAST_MATH__ to remain predefined even when the full set of fast math options is not actually in effect. This is fixed here by adding those flags into the fast_math_flags_set_p test. This affects the following flags: -fcx-limited-range -fassociative-math -freciprocal-math 3. For some math flags, set_fast_math_flags has code that sets their values only to what is already their default. The overall effect of this code is a complete no-op. This patch removes that dead code. This affects the following flags: -frounding-math -fsignaling-nans The overall effect of this patch is that now all component flags of -ffast-math are treated exactly equivalently: * they are set (changed from their default) with -ffast-math * they are reset to their default with -fno-fast-math * __FAST_MATH__ is only defined if the value of the flag matches what -ffast-math would have set it to Tested on s390x-ibm-linux. OK for mainline? Bye, Ulrich ChangeLog: * opts.c (set_fast_math_flags): In the !set case, also reset x_flag_cx_limited_range and x_flag_excess_precision. Remove dead code resetting x_flag_signaling_nans and x_flag_rounding_math. (fast_math_flags_set_p): Also test x_flag_cx_limited_range, x_flag_associative_math, and x_flag_reciprocal_math. diff --git a/gcc/opts.c b/gcc/opts.c index 7affeb4..4452793 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2850,18 +2850,14 @@ set_fast_math_flags (struct gcc_options *opts, int set) opts->x_flag_finite_math_only = set; if (!opts->frontend_set_flag_errno_math) opts->x_flag_errno_math = !set; - if (set) - { - if (opts->frontend_set_flag_excess_precision == EXCESS_PRECISION_DEFAULT) - opts->x_flag_excess_precision - = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT; - if (!opts->frontend_set_flag_signaling_nans) - opts->x_flag_signaling_nans = 0; - if (!opts->frontend_set_flag_rounding_math) - opts->x_flag_rounding_math = 0; - if (!opts->frontend_set_flag_cx_limited_range) - opts->x_flag_cx_limited_range = 1; - } + if (!opts->frontend_set_flag_cx_limited_range) + opts->x_flag_cx_limited_range = set; + if (!opts->frontend_set_flag_excess_precision) + opts->x_flag_excess_precision + = set ? EXCESS_PRECISION_FAST : EXCESS_PRECISION_DEFAULT; + + // -ffast-math should also reset -fsignaling-nans and -frounding-math, + // but since those are off by default, there's nothing to do for now. } /* When -funsafe-math-optimizations is set the following @@ -2884,10 +2880,13 @@ bool fast_math_flags_set_p (const struct gcc_options *opts) { return (!opts->x_flag_trapping_math + && !opts->x_flag_signed_zeros + && opts->x_flag_associative_math + && opts->x_flag_reciprocal_math && opts->x_flag_unsafe_math_optimizations && opts->x_flag_finite_math_only - && !opts->x_flag_signed_zeros && !opts->x_flag_errno_math + && opts->x_flag_cx_limited_range && opts->x_flag_excess_precision == EXCESS_PRECISION_FAST); }