From patchwork Fri Oct 9 16:17:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 528292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 92D0014029C for ; Sat, 10 Oct 2015 03:17:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PeF15cR/; dkim-atps=neutral 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:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=me3GKcMfNJQ/B5BuXlPHJ/sELOOkHIOyutV5p3HA2HLrrFd8nU5ia FibALmQzcMjTyKvTzzBstgjYbtd0h1F7coSu8G1/lFTTcgbvu/QRLKyXBG02r/em Rir3j9kqbdFaWpsJzaX9duLAtwss6v9zcLWn1DfVJSoPbz8uD7m+ew= 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:references:date:in-reply-to:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=zYks8Z73ymKga39dp4/+pWmJfKE=; b=PeF15cR/H6yuBOAbtiZtFpJKzPvY z/OUczOoWTsRyWSC/Xt+WC68OM9hdnKhtG/hJ4HcixVT5xh1mWrtQA4bXk89Vgn5 5vuGkgKjRyTEjMMxlUek5XS5qPwZESLQuoVnx/2mYbcxAjmv+iRBWY/8aYlFJI5Y +sIrtv4K1dSIerY= Received: (qmail 3980 invoked by alias); 9 Oct 2015 16:17:17 -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 3971 invoked by uid 89); 9 Oct 2015 16:17:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Oct 2015 16:17:15 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-9-xLC-ppuxSC2EDJmig-VNXQ-1; Fri, 09 Oct 2015 17:17:11 +0100 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 9 Oct 2015 17:17:11 +0100 From: Richard Sandiford To: Christophe Lyon Mail-Followup-To: Christophe Lyon , "gcc-patches\@gcc.gnu.org" , richard.sandiford@arm.com Cc: "gcc-patches\@gcc.gnu.org" Subject: Re: Move sqrt and cbrt simplifications to match.pd References: <87k2r1bb0p.fsf@e105548-lin.cambridge.arm.com> <87twq19u6s.fsf@e105548-lin.cambridge.arm.com> <87pp0o9j2z.fsf@e105548-lin.cambridge.arm.com> Date: Fri, 09 Oct 2015 17:17:10 +0100 In-Reply-To: <87pp0o9j2z.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Fri, 09 Oct 2015 16:07:16 +0100") Message-ID: <87lhbc9fuh.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: xLC-ppuxSC2EDJmig-VNXQ-1 Richard Sandiford writes: > Christophe Lyon writes: >> On 8 October 2015 at 18:55, Richard Sandiford >> wrote: >>> Marc Glisse writes: >>>> On Mon, 5 Oct 2015, Richard Sandiford wrote: >>>> >>>>> + /* cbrt(sqrt(x)) -> pow(x,1/6). */ >>>>> + (simplify >>>>> + (sqrts (cbrts @0)) >>>>> + (pows @0 { build_real_truncate (type, dconst<1, 6> ()); })) >>>>> + /* sqrt(cbrt(x)) -> pow(x,1/6). */ >>>>> + (simplify >>>>> + (cbrts (sqrts @0)) >>>>> + (pows @0 { build_real_truncate (type, dconst<1, 6> ()); })) >>>> >>>> I think you swapped the comments (not that it matters). >>> >>> Thanks, fixed in the committed version. >>> >>> Richard >>> >> Hi Richard, >> >> Since you committed this patch, I've noticed that gcc.dg/builtins-10.c fails >> on arm-none-linux-gnueabi targets (as opposed to arm-none-linux-gnueabihf). >> >> gcc.log shows: >> /cchfHDHc.o: In function `test': >> builtins-10.c:(.text+0x60): undefined reference to `link_error' >> collect2: error: ld returned 1 exit status > > Looks like this is the same fold_strip_sign_ops problem that I was seeing > with some WIP follow-on patches. We don't fold pow(abs(x), 4) to pow(x, 4). Here's the patch I'm testing. Thanks, Richard gcc/ * real.h (real_isinteger): Declare. * real.c (real_isinteger): New function. * match.pd: Simplify pow(|x|,y) and pow(-x,y) to pow(x,y) if y is an even integer. diff --git a/gcc/match.pd b/gcc/match.pd index b87c436..67f9d54 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -309,12 +309,19 @@ along with GCC; see the file COPYING3. If not see && TYPE_OVERFLOW_UNDEFINED (type)) @0))) -/* Simplify cos (-x) -> cos (x). */ (for op (negate abs) -(for coss (COS COSH) - (simplify - (coss (op @0)) - (coss @0)))) + /* Simplify cos(-x) and cos(|x|) -> cos(x). Similarly for cosh. */ + (for coss (COS COSH) + (simplify + (coss (op @0)) + (coss @0))) + /* Simplify pow(-x, y) and pow(|x|,y) -> pow(x,y) if y is an even integer. */ + (for pows (POW) + (simplify + (pows (op @0) REAL_CST@1) + (with { HOST_WIDE_INT n; } + (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0) + (pows @0 @1)))))) /* X % Y is smaller than Y. */ (for cmp (lt ge) diff --git a/gcc/real.c b/gcc/real.c index f633ffd..85ac83d 100644 --- a/gcc/real.c +++ b/gcc/real.c @@ -4997,6 +4997,24 @@ real_isinteger (const REAL_VALUE_TYPE *c, machine_mode mode) return real_identical (c, &cint); } +/* Check whether C is an integer that fits in a HOST_WIDE_INT, + storing it in *INT_OUT if so. */ + +bool +real_isinteger (const REAL_VALUE_TYPE *c, HOST_WIDE_INT *int_out) +{ + REAL_VALUE_TYPE cint; + + HOST_WIDE_INT n = real_to_integer (c); + real_from_integer (&cint, VOIDmode, n, SIGNED); + if (real_identical (c, &cint)) + { + *int_out = n; + return true; + } + return false; +} + /* Write into BUF the maximum representable finite floating-point number, (1 - b**-p) * b**emax for a given FP format FMT as a hex float string. LEN is the size of BUF, and the buffer must be large diff --git a/gcc/real.h b/gcc/real.h index 706859b..e65b526 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -467,7 +467,8 @@ extern void real_round (REAL_VALUE_TYPE *, machine_mode, extern void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); /* Check whether the real constant value given is an integer. */ -extern bool real_isinteger (const REAL_VALUE_TYPE *c, machine_mode mode); +extern bool real_isinteger (const REAL_VALUE_TYPE *, machine_mode); +extern bool real_isinteger (const REAL_VALUE_TYPE *, HOST_WIDE_INT *); /* Write into BUF the maximum representable finite floating-point number, (1 - b**-p) * b**emax for a given FP format FMT as a hex