From: Richard Sandiford <richard.sandiford@arm.com>
To: Christophe Lyon <christophe.lyon@linaro.org>
Cc: "gcc-patches\@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: Move sqrt and cbrt simplifications to match.pd
Date: Fri, 09 Oct 2015 16:17:00 -0000 [thread overview]
Message-ID: <87lhbc9fuh.fsf@e105548-lin.cambridge.arm.com> (raw)
In-Reply-To: <87pp0o9j2z.fsf@e105548-lin.cambridge.arm.com> (Richard Sandiford's message of "Fri, 09 Oct 2015 16:07:16 +0100")
Richard Sandiford <richard.sandiford@arm.com> writes:
> Christophe Lyon <christophe.lyon@linaro.org> writes:
>> On 8 October 2015 at 18:55, Richard Sandiford
>> <richard.sandiford@arm.com> wrote:
>>> Marc Glisse <marc.glisse@inria.fr> 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
next prev parent reply other threads:[~2015-10-09 16:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 15:17 Richard Sandiford
2015-10-06 8:13 ` Richard Biener
2015-10-06 8:59 ` Marc Glisse
2015-10-08 16:55 ` Richard Sandiford
2015-10-09 14:35 ` Christophe Lyon
2015-10-09 15:07 ` Richard Sandiford
2015-10-09 16:17 ` Richard Sandiford [this message]
2015-10-12 10:01 ` Richard Biener
2015-10-12 14:11 ` Christophe Lyon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lhbc9fuh.fsf@e105548-lin.cambridge.arm.com \
--to=richard.sandiford@arm.com \
--cc=christophe.lyon@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).