From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84838 invoked by alias); 20 Feb 2018 02:49:39 -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 84812 invoked by uid 89); 20 Feb 2018 02:49:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Delay X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Feb 2018 02:49:34 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 650A9EAE98 for ; Tue, 20 Feb 2018 02:49:29 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-85.brq.redhat.com [10.40.204.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8528210AF9EE for ; Tue, 20 Feb 2018 02:49:21 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w1JM2qf2019243; Mon, 19 Feb 2018 23:02:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w1JM2oXP019242; Mon, 19 Feb 2018 23:02:50 +0100 Date: Tue, 20 Feb 2018 02:49:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Defer pow (C, x) folding until after vectorization always (PR middle-end/82004) Message-ID: <20180219220250.GX5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg01140.txt.bz2 Hi! While I've over-simplified the testcase and so this patch doesn't help the 628.pop2_s miscompare, I still believe it is beneficial to defer this folding until late for these reasons: 1) if we propagate a constant into the second pow argument too, it will be likely more precise than going through the exp (cst * x) way 2) except when C is M_E, pow is fewer operations and thus smaller IL Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-02-19 Jakub Jelinek PR middle-end/82004 * match.pd (pow(C,x) -> exp(log(C)*x)): Delay all folding until after vectorization. * gfortran.dg/pr82004.f90: New test. --- gcc/match.pd.jj 2018-02-15 12:15:51.655780636 +0100 +++ gcc/match.pd 2018-02-19 17:38:06.390763194 +0100 @@ -4006,7 +4006,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (pows REAL_CST@0 @1) (if (real_compare (GT_EXPR, TREE_REAL_CST_PTR (@0), &dconst0) - && real_isfinite (TREE_REAL_CST_PTR (@0))) + && real_isfinite (TREE_REAL_CST_PTR (@0)) + /* As libmvec doesn't have a vectorized exp2, defer optimizing + the use_exp2 case until after vectorization. It seems actually + beneficial for all constants to postpone this until later, + because exp(log(C)*x), while faster, will have worse precision + and if x folds into a constant too, that is unnecessary + pessimization. */ + && canonicalize_math_after_vectorization_p ()) (with { const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (@0); bool use_exp2 = false; @@ -4021,10 +4028,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) } (if (!use_exp2) (exps (mult (logs @0) @1)) - /* As libmvec doesn't have a vectorized exp2, defer optimizing - this until after vectorization. */ - (if (canonicalize_math_after_vectorization_p ()) - (exp2s (mult (log2s @0) @1)))))))) + (exp2s (mult (log2s @0) @1))))))) (for sqrts (SQRT) cbrts (CBRT) --- gcc/testsuite/gfortran.dg/pr82004.f90.jj 2018-02-19 17:58:57.435682156 +0100 +++ gcc/testsuite/gfortran.dg/pr82004.f90 2018-02-19 17:58:34.127684892 +0100 @@ -0,0 +1,18 @@ +! PR middle-end/82004 +! { dg-do run } +! { dg-options "-Ofast" } + + integer, parameter :: r8 = selected_real_kind(13), i4 = kind(1) + integer (i4), parameter :: a = 400, b = 2 + real (r8), parameter, dimension(b) :: c = (/ .001_r8, 10.00_r8 /) + real (r8) :: d, e, f, g, h + real (r8), parameter :: j & + = 10**(log10(c(1))-(log10(c(b))-log10(c(1)))/real(a)) + + d = c(1) + e = c(b) + f = (log10(e)-log10(d))/real(a) + g = log10(d) - f + h = 10**(g) + if (h.ne.j) stop 1 +end Jakub