This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Simplify nested FP conversions in convert.c II
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at cygnus dot com
- Date: Mon, 10 Feb 2003 14:04:45 +0100
- Subject: Simplify nested FP conversions in convert.c II
Hi,
here is updated patch that should match what we ended up with in
combine.c
Sun Feb 9 19:02:57 CET 2003 Jan Hubicka <jh@suse.cz>
* convert.c (convert_to_real): Simplify nested conversions.
Index: convert.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/convert.c,v
retrieving revision 1.27
diff -c -3 -p -r1.27 convert.c
*** convert.c 25 Jan 2003 11:08:38 -0000 1.27
--- convert.c 10 Feb 2003 13:02:39 -0000
*************** convert_to_real (type, expr)
*** 204,209 ****
--- 204,247 ----
if (itype != type && FLOAT_TYPE_P (type))
switch (TREE_CODE (expr))
{
+ case NOP_EXPR:
+ case CONVERT_EXPR:
+ {
+ tree op = TREE_OPERAND (expr, 0);
+
+ if (FLOAT_TYPE_P (TREE_TYPE (expr))
+ && FLOAT_TYPE_P (TREE_TYPE (op))
+ /* Nested floating point extension can be always
+ elliminated. */
+ && ((TYPE_PRECISION (TREE_TYPE (op))
+ < TYPE_PRECISION (TREE_TYPE (expr)))
+ /* Chained float truncates can be elliminated too
+ when we don't care about double rounding. */
+ || (flag_unsafe_math_optimizations
+ && (TYPE_PRECISION (TREE_TYPE (expr))
+ < TYPE_PRECISION (TREE_TYPE (op)))
+ && (TYPE_PRECISION (type)
+ < TYPE_PRECISION (TREE_TYPE (op))))))
+ return convert (type, op);
+ }
+ case FLOAT_EXPR:
+ {
+ tree op = TREE_OPERAND (expr, 0);
+
+ if (INTEGRAL_TYPE_P (TREE_TYPE (op))
+ /* (float)(double)int == (float)int
+ when we don't care about double rounding */
+ && ((flag_unsafe_math_optimizations
+ && (TYPE_PRECISION (TREE_TYPE (expr))
+ > TYPE_PRECISION (TREE_TYPE (op))))
+ /* (double)(float)short == (double)short.
+ When the later FP type is large enought
+ to hold the integer. */
+ || (TYPE_PRECISION (TREE_TYPE (expr))
+ >= TYPE_PRECISION (TREE_TYPE (op)))))
+ return convert (type, op);
+ }
+ break;
/* convert (float)-x into -(float)x. This is always safe. */
case ABS_EXPR:
case NEGATE_EXPR: