From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90386 invoked by alias); 18 Aug 2017 13:43:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 88429 invoked by uid 89); 18 Aug 2017 13:43:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Aug 2017 13:43:54 +0000 Received: by mail-wm0-f51.google.com with SMTP id u29so67272wma.0 for ; Fri, 18 Aug 2017 06:43:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Ba+F8rxQivySeX+ZRzvWL2vg7Jw1UVNHzpFybUvJrao=; b=TXO71CUxRtuB0YDayEMBSOasR8pWvfKPl8x7viVSxQCpdZZhs18dy8oN6moRh+vcF1 gl/5YHZ19MZyjkp+A0BbLrCWhPb8hxlRHiTq7qFjSTI+f+0jEesGNJPixI7XHDpF8EJS puvV7B9To89Nqzgt3A3VjzkiZYn4HgzNbBOEMKPyoCvJGEXywarOb1uvukSAO2vgRKfA VTrixK9WgZP+BldV2AMvW0PHkmNu1Te24i7P6uPDFb0bd9h9l9f4/3tNzeuYJ8fl9eVq hmkp+w1BO0ebV+w2QNw2RpK7LbMJNXws/jan2FsyGc7tb4d9p0anp4ZuTzpn/Ah6YC5+ l4GQ== X-Gm-Message-State: AHYfb5iEU2X0YREIIE43MXvCKMI7dK2AFpDVT2IUxRS6JPo6xVRwNW1X D+l3sY1SjqFWuDkCAeyj/rn852mUyQ== X-Received: by 10.80.167.65 with SMTP id h59mr4900057edc.142.1503063831878; Fri, 18 Aug 2017 06:43:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.180.249 with HTTP; Fri, 18 Aug 2017 06:43:51 -0700 (PDT) In-Reply-To: References: From: Richard Biener Date: Fri, 18 Aug 2017 14:05:00 -0000 Message-ID: Subject: Re: [PATCH v2] Simplify pow with constant To: Wilco Dijkstra Cc: Alexander Monakov , GCC Patches , nd Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg01132.txt.bz2 On Fri, Aug 18, 2017 at 2:47 PM, Wilco Dijkstra wrote: > 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. You can use exp10/pow10 in match.pd but it will only match if the programmer already uses those functions as they are not C standard. There's also exp2 which is a C99 function. Is there any good reason to convert exp (C * x) to exp2 (C' * x)? (besides if C' becomes 1) So eventually we can match pow (10., x) -> exp10 and pow (2., x) -> exp2 (though I believe in canonicalization as well -- all exp calls could be canonicalized to pow calls to simplify the cases we need to handle...). The patch is ok. Thanks, Richard. > 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) > >