From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39617 invoked by alias); 12 Oct 2015 14:11:27 -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 39602 invoked by uid 89); 12 Oct 2015 14:11:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f49.google.com Received: from mail-qg0-f49.google.com (HELO mail-qg0-f49.google.com) (209.85.192.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 12 Oct 2015 14:11:25 +0000 Received: by qgez77 with SMTP id z77so121060175qge.1 for ; Mon, 12 Oct 2015 07:11:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=Mm2ru/qRqYMcl3hUP+h1UEJefrQFGzqFiptSHcZxuoo=; b=iaxQzeWKPPKNT8sfJZE4kenpBOcTVEJ2d5BlK7SStyU2ymJ21SPNmdJmbc7IXsROuh St1MolE31adYnGsZqoUXDxg7lQ7lbRm8SQYqQsZp4fOP+KKg5QbjtsqUAPXExeUVrpxX E3QaDIvkbvmaJFtX/Cj1dZmkWjNKZK+su8LydPwdTbn/OtF24D3pJoqP+zR+tV2Wxt/R STnq6WGha/HHa2Pq6a/mSv1TzhuISH0rauDgm/zXw4OHU0tLO+fWbSG6csZjNcbKN6/W mlVDXZbUqohfiz2nib5iLEZRbvAMwWVJIxT3ILPK39scd4yekSBCgPjJEYc3753J0svP uSDw== X-Gm-Message-State: ALoCoQmiEwULIuE/TiVu6/z1WjlY+noDA7dyggNtsvosLKvjiIrmz7bS7cZCqNIMcMt9M3UbCZTu MIME-Version: 1.0 X-Received: by 10.140.130.72 with SMTP id 69mr34115176qhc.32.1444659083292; Mon, 12 Oct 2015 07:11:23 -0700 (PDT) Received: by 10.140.44.10 with HTTP; Mon, 12 Oct 2015 07:11:23 -0700 (PDT) In-Reply-To: <87lhbc9fuh.fsf@e105548-lin.cambridge.arm.com> References: <87k2r1bb0p.fsf@e105548-lin.cambridge.arm.com> <87twq19u6s.fsf@e105548-lin.cambridge.arm.com> <87pp0o9j2z.fsf@e105548-lin.cambridge.arm.com> <87lhbc9fuh.fsf@e105548-lin.cambridge.arm.com> Date: Mon, 12 Oct 2015 14:11:00 -0000 Message-ID: Subject: Re: Move sqrt and cbrt simplifications to match.pd From: Christophe Lyon To: Christophe Lyon , "gcc-patches@gcc.gnu.org" , Richard Sandiford Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg01134.txt.bz2 On 9 October 2015 at 18:17, Richard Sandiford wrote: > 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. > This makes sense indeed. I was wondering why I didn't notice regressions on arm-*hf targets: are such optimizations caught in later passes for some targets? > 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 >