From patchwork Fri Aug 18 12:47:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 803219 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-460566-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="viUha805"; 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 3xYjXl3snVz9t3G for ; Fri, 18 Aug 2017 22:47:33 +1000 (AEST) 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:references:in-reply-to :content-type:content-transfer-encoding:mime-version; q=dns; s= default; b=XdN9p1a7Jc0r0O37HICTCTchOrjLXeSFxvMZpklIA2vh9lDDNOcOi mD6BFd9MlMrFsNe3FcD417lQwwGUuJPB5fJwdfYWsOmZ1zyBk6Nq35hdIzZ5DexJ 6Hm1UtE7NJq0RNMSAuuEqf4zIwuuueNUXr0RH+4If6OY2QFlGEblLo= 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:references:in-reply-to :content-type:content-transfer-encoding:mime-version; s=default; bh=j9EY1HksZApG0xPQstYq8qazrnc=; b=viUha805aOtv0+iEAfzIeWxXlf0T tT48CSlK7ie1R1OBKeAzzF6NS4GtWzKZ9B0ekMQxj6nbTJ4sxlVXpqG7/CUxQyvB C3IGChoIFrSxUnYtI3uOC/lM6ln0ynSUyYGh3GVyupdxTAs9rvX70vYz/llcE7th Q9DVju3oOf4UN9k= Received: (qmail 43745 invoked by alias); 18 Aug 2017 12:47:25 -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 39722 invoked by uid 89); 18 Aug 2017 12:47:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10056.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.56) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Aug 2017 12:47:20 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com (10.168.86.22) by DB6PR0801MB2071.eurprd08.prod.outlook.com (10.168.86.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1362.18; Fri, 18 Aug 2017 12:47:16 +0000 Received: from DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::2d78:6ac0:142:cc9a]) by DB6PR0801MB2053.eurprd08.prod.outlook.com ([fe80::2d78:6ac0:142:cc9a%18]) with mapi id 15.01.1362.019; Fri, 18 Aug 2017 12:47:16 +0000 From: Wilco Dijkstra To: Alexander Monakov CC: GCC Patches , Richard Biener , nd Subject: Re: [PATCH v2] Simplify pow with constant Date: Fri, 18 Aug 2017 12:47:16 +0000 Message-ID: References: , , , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0801MB2071; 6:HvLwTKOf6NlIRRjiDjCwhOoFZEEoHZD8+e/JxMD1KAUOSX9lYlqkeCiFODGzGw+T4jj8u6rYbkmdKo2URLvsz2t6wlJXRvtx4mxDdiN7RAv6h2Guwhl8pRcN0dniDChbwvN7He4t3lI329IlSWEk9hiEqe+3qSUqkES1blU81ec1YgV3JXotKED7uSB69nEunhW2w01GmGyEmzH4BX1OjsXnhwlsTY/vmPo/fudAnxtp+u6cX+YRTWtUmw/ejpO/TKRwBN9MV8v5GkYRDbL/p62hr/W/kS0pFCYVyeiGyPKL914LVr8QEuTw3eqCHEfs8Bs4l7tyqLNpB5/88aZHfg==; 5:LMfZHOhS9295+V0WI05h9EnwTR1qASc9sRmvPus7i0MxYLA9+bUE5g9SiY1T25g+uNK9+8LcB6lbSWDGlwB2+BiT8qeYXhDxg3mpJeU6nLp4yodaeiK0RTza1m2VJKl+l1oN5O1EtfQG5WAWFJRfew==; 24:dukJQ/k416lP6oHbe94wOgAne5WzqR1KMTWVBsr2kyGYnYTuvdNPdXmFsO1bCIeG73RAWJavnQgec7oRcq+z12604p0YJGQaN5PEo5UG/o4=; 7:v1HtvF0GUhkSFjKEuIhx+6MQIDBstHuiqXzx336UrYc8EecA2pY/3nPnOJFFyY3Iu/KqLyLVXmTAh7ZbiVNnI9JeEBL0eLCLVzoY51EVGOH9kQjNvZ/xPUgwUX41m6DhYlGt7o5MUXVXyGmw6Urh/6qfltjGktgsaqwtrYsSohVMs3W+ZDqkA/qo6fFsCR6SoaTRBjDXKsYh5gW3BsThbBi9wZILPzVQID4TzN8oYIc= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: abaf229f-0a6b-4b9d-7622-08d4e63741b6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DB6PR0801MB2071; x-ms-traffictypediagnostic: DB6PR0801MB2071: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123558100)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB6PR0801MB2071; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB6PR0801MB2071; x-forefront-prvs: 040359335D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(377424004)(24454002)(189002)(199003)(54534003)(6116002)(110136004)(3846002)(2906002)(478600001)(33656002)(106356001)(50986999)(4326008)(54356999)(66066001)(3660700001)(76176999)(3280700002)(6246003)(101416001)(189998001)(39060400002)(102836003)(2900100001)(68736007)(25786009)(74316002)(9686003)(81156014)(105586002)(97736004)(229853002)(72206003)(8936002)(5660300001)(7696004)(93886005)(53936002)(81166006)(8676002)(7736002)(6916009)(2950100002)(305945005)(14454004)(86362001)(99286003)(5250100002)(55016002)(54906002)(6436002)(6506006); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB2071; H:DB6PR0801MB2053.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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-originalarrivaltime: 18 Aug 2017 12:47:16.5211 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2071 Alexander Monakov wrote: > > Note this changes the outcome for C == +Inf, x == 0 (pow is specified to > return 1.0 in that case, but x * C1 == NaN).  There's another existing > transform with the same issue, 'pow(expN(x), y) -> expN(x*y)', so this is > not a new problem. > > The whole set of these match.pd transforms is guarded by > flag_unsafe_math_optimizations, which is a bit strange, on the one hand > it does not include -ffinite-math-only, but on the other hand it's > defined broadly enough to imply that. Yes I was assuming that unsafe_math_optimizations was enough for these transformations to be... safe. I've added an isfinite check so that case works fine. It looks we need to go through the more complex transformations (especially given pow has so many special cases) and add more finite_math checks. Here's the new version: This patch simplifies pow (C, x) into exp (x * C1) if C > 0, C1 = log (C). Do this only for fast-math as accuracy is reduced. This is much faster since pow is more complex than exp - with current GLIBC the speedup is more than 7 times for this transformation. The worst-case ULP error of the transformation for powf (10.0, x) in SPEC was 2.5. If we allow use of exp10 in match.pd, the ULP error would be lower. ChangeLog: 2017-08-18 Wilco Dijkstra * match.pd: Add pow (C, x) simplification. diff --git a/gcc/match.pd b/gcc/match.pd index 0e36f46b914bc63c257cef47152ab1aa507963e5..a5552c5096de5100a882d52add6b620ba87c1f72 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3622,6 +3622,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (logs (pows @0 @1)) (mult @1 (logs @0)))) + /* pow(C,x) -> exp(log(C)*x) if C > 0. */ + (for pows (POW) + exps (EXP) + logs (LOG) + (simplify + (pows REAL_CST@0 @1) + (if (real_compare (GT_EXPR, TREE_REAL_CST_PTR (@0), &dconst0) + && real_isfinite (TREE_REAL_CST_PTR (@0))) + (exps (mult (logs @0) @1))))) + (for sqrts (SQRT) cbrts (CBRT) pows (POW)