summaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2015-10-13 07:34:41 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2015-10-13 07:34:41 +0000
commit9b054b08813d37586d6765fd087b0fc85dc94daf (patch)
treece58f25ea3acb2f496d0e9a22bb891f6e38e668d /gcc/real.c
parent6696de8a7f7e9bf37e2b9358ad5608dc863ad7a4 (diff)
To...
To: gcc-patches@gcc.gnu.org Subject: Add an extra pow rule to match.pd From: Richard Sandiford <richard.sandiford@arm.com> Gcc: private.sent --text follows this line-- Simplify pow(|x|,y) and pow(-x,y) to pow(x,y) if y is an even integer. At the moment this duplicates a case in fold_builtin_pow, but an upcoming patch will move all the fold_builtin_pow rules to match.pd. I'm doing this one early to fix a regression in builtin-10.c for soft-float ARM. 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. From-SVN: r228750
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/real.c b/gcc/real.c
index f633ffd2e88..85ac83d3fdc 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