From patchwork Thu Nov 16 14:33:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 838599 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466996-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="JF7Y5OrW"; 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 3yd3dM0j40z9s7G for ; Fri, 17 Nov 2017 01:33:25 +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:from :to:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=Ba4 9NL+xeNG0OPOZRnABxCupVM1UegQGWYGh6BtlS52XavwQP6T2GKdUuXCadlvvl35 xN3QTqFuw9D3URyYywZj+l76S9DO07eLdy6L89X+SmfMQ7mbFAMiigfxwKP9kxeo lAJvyM4UbesDDxs5z3xoqdYK/173te6dTLfD3oBo= 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:from :to:cc:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=default; bh=TGIQdvl9n 4i4zqO9ZihGQmlcMpU=; b=JF7Y5OrW5/pZAS6GXCYn4t2ILkK3IFzEQygTsBb5w IlD+laay1HM6vcoEGIZM9RTkylyvaZ+ht2iTzC8/o700aKxpOfTepCnRTmD17m0z IdSKiuEm2eTM1uUsfU6iDzF2He+i+SZ/abUI87U9U/C1XW3SmUZCvDSowXzJ+C+C Cg= Received: (qmail 98428 invoked by alias); 16 Nov 2017 14:33:16 -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 98141 invoked by uid 89); 16 Nov 2017 14:33:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=nonstop, non-stop X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10058.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Nov 2017 14:33:13 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR0801MB2056.eurprd08.prod.outlook.com (10.168.86.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Thu, 16 Nov 2017 14:33:09 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::9cdc:27e2:bc30:67f7]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::9cdc:27e2:bc30:67f7%17]) with mapi id 15.20.0218.011; Thu, 16 Nov 2017 14:33:09 +0000 From: Wilco Dijkstra To: GCC Patches CC: nd Subject: [PATCH] Disable -ftrapping-math by default Date: Thu, 16 Nov 2017 14:33:09 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2056; 6:o1gBg+L2AgyxVzYfk7WvilGhOOyRUjIa3VsinVqvxroFdj4uUV51iinHO32Csxi18mV+5+NDphLyrSGHVOfr1A/thHLo4K9qZcITiVvT2A4YLhK2nSKFXZNCxR/3vQuYoX/O9UQjQNX8kHqwjAKHXRaeekkBKRwebMXAIaD8H5ZzgFMvSjiCtFb858GX8KsJkrg4HzBwp4ZtCSxz2sy1iP7YQ/KY7fVFubIBktS3nUJIlmMymAn4/1gVk8ZdVeVj6Syt8C/uLqnpe5yEKo4OMYV23uKc8rhZWdUzV+Lg+FEWeZof9LLwXPsUFcUADZFtR7vz4Btd2/S0h3l1c64SLn+1Pd/txauaFBxMb1Swh2o=; 5:vKa0n7T70gac7+kcofv5VErqeK+iLK4MJn4BSQPApBBf4KGIIJHUHqoXGY9JBz9FBwT2tUD+F1OOSdAi/K8GxP56YvTB4Fkt2QkdXMmcP5qthrOfpDnJthVmdAzcaYjgNQFAz7sR29NapAoSvo6xgVkC0M7t3yOPKR7Is9/spg8=; 24:ePHP7416lqQAqYL0OGTdKq/jy7O6wFPH/FDgIY/wCKKwZj4TDWiaL0f2xLJr7Bnnovx7rlW+GcIQxuN4I/B4GFjggcnJy1v+MCbjC3LWeQM=; 7:Kdo0e1I1x3V9KIkKFACyJKCX0C4pRN2MoemRpgNnd3h/sc9rQNEulHq8/VixYIOGALLNyo9gSMGkcOi2lTxQTcOx3P7eNKtuE9lua0oYxzi+xUW0JsoroDCWqcg5l8TFZXGX9gkr4s2fufMkMnjw4BTDCALi5i1aZLKKj/OHVjRKKPEii2fudDONOfF5uUUthABUtQsCxYtzLovRBEk9DGAiU6SwXooNs4uwsp4fzELgrUMqi/pHmaKmKyGlYBB0 x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 07590846-2ff9-4bad-f98a-08d52cfef575 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603199); SRVR:DB6PR0801MB2056; x-ms-traffictypediagnostic: DB6PR0801MB2056: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3231022)(10201501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(20161123560025)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB2056; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB2056; x-forefront-prvs: 0493852DA9 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(199003)(377424004)(189002)(5660300001)(3660700001)(3280700002)(6916009)(3846002)(5250100002)(305945005)(55016002)(7696004)(81156014)(2906002)(189998001)(33656002)(81166006)(2900100001)(106356001)(102836003)(316002)(8676002)(105586002)(97736004)(9686003)(6436002)(6506006)(53936002)(86362001)(72206003)(8936002)(4001150100001)(14454004)(6116002)(7736002)(4326008)(74316002)(99286004)(54356999)(25786009)(101416001)(68736007)(50986999)(66066001)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2056; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07590846-2ff9-4bad-f98a-08d52cfef575 X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Nov 2017 14:33:09.3320 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2056 GCC currently defaults to -ftrapping-math. This is supposed to generate code for correct user-visible traps and FP status flags. However it doesn't work as expected since it doesn't block any floating point optimizations. For example it continues to perform CSE, moves FP operations across calls, moves FP operations out of loops, constant folds and removes dead floating point operations that cause exceptions. Given the majority of code doesn't contain user trap handlers or inspects FP status flags, there is no point in enabling it even if it worked as expected. Simple case that should cause a FP exception: void f(void) { 0.0 / 0.0; } Compiles to: f: ret OK for commit? 2017-11-16 Wilco Dijkstra * common.opt (ftrapping-math): Change default to 0. * doc/invoke.texi (-ftrapping-math): Update documentation. diff --git a/gcc/common.opt b/gcc/common.opt index 1bb87353f760d7c60c39de8b9de4311c1ec3d892..59940c64356964f8f9b9d842ad3f1a1c02548bab 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2470,7 +2470,7 @@ generate them instead of using descriptors. ; (user-visible) trap. This is the case, for example, in nonstop ; IEEE 754 arithmetic. ftrapping-math -Common Report Var(flag_trapping_math) Init(1) Optimization SetByCombined +Common Report Var(flag_trapping_math) Init(0) Optimization SetByCombined Assume floating-point operations can trap. ftrapv diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 74c33ea35b9f320b419a3417e6007d2391536f1b..3673b34b3b7f7b57cfa6375b5316f9f282a9e9bb 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -9479,20 +9479,21 @@ This option implies that the sign of a zero result isn't significant. The default is @option{-fsigned-zeros}. -@item -fno-trapping-math -@opindex fno-trapping-math -Compile code assuming that floating-point operations cannot generate +@item -ftrapping-math +@opindex ftrapping-math +Compile code assuming that floating-point operations can generate user-visible traps. These traps include division by zero, overflow, -underflow, inexact result and invalid operation. This option requires -that @option{-fno-signaling-nans} be in effect. Setting this option may -allow faster code if one relies on ``non-stop'' IEEE arithmetic, for example. +underflow, inexact result and invalid operation. -This option should never be turned on by any @option{-O} option since -it can result in incorrect output for programs that depend on -an exact implementation of IEEE or ISO rules/specifications for -math functions. +Note this option has only been partially implemented and does not work +as expected. For example @option{-ftrapping-math} performs floating +point optimizations such as loop invariant motion, constant folding +and scheduling across function calls which have user-visible effects +on FP exception flags. + +This option is turned on when using @option{-fsignaling-nans}. -The default is @option{-ftrapping-math}. +The default is @option{-fno-trapping-math}. @item -frounding-math @opindex frounding-math