aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorYury Gribov <tetra2005@gmail.com>2018-10-12 20:35:20 +0000
committerYury Gribov <ygribov@gcc.gnu.org>2018-10-12 20:35:20 +0000
commite41ec71bd97a1a8eaef40695c7ae9b7f4b1fc819 (patch)
treed9f2071404e3120d9043af8e3800ed5d14c14b8c /gcc/real.c
parent67aeaded2f8dabe16b4879261c6b6ddda6b53cd2 (diff)
downloadgcc-e41ec71bd97a1a8eaef40695c7ae9b7f4b1fc819.zip
gcc-e41ec71bd97a1a8eaef40695c7ae9b7f4b1fc819.tar.gz
gcc-e41ec71bd97a1a8eaef40695c7ae9b7f4b1fc819.tar.bz2
Add pattern to remove useless float casts in comparisons.
PR middle-end/81376 gcc/ * real.c (format_helper::can_represent_integral_type_p): New function * real.h (format_helper::can_represent_integral_type_p): Ditto. * match.pd: New pattern. gcc/testsuite/ * c-c++-common/pr81376.c: New test. * gcc.target/i386/387-ficom-2.c: Update test. * gcc.target/i386/387-ficom-2.c: Ditto. From-SVN: r265131
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 51f8fd5..0e2da25 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -5176,6 +5176,19 @@ get_max_float (const struct real_format *fmt, char *buf, size_t len)
gcc_assert (strlen (buf) < len);
}
+/* True if all values of integral type can be represented
+ by this floating-point type exactly. */
+
+bool format_helper::can_represent_integral_type_p (tree type) const
+{
+ gcc_assert (! decimal_p () && INTEGRAL_TYPE_P (type));
+
+ /* INT?_MIN is power-of-two so it takes
+ only one mantissa bit. */
+ bool signed_p = TYPE_SIGN (type) == SIGNED;
+ return TYPE_PRECISION (type) - signed_p <= significand_size (*this);
+}
+
/* True if mode M has a NaN representation and
the treatment of NaN operands is important. */