From 77f9af81d26ddde9326b63bfc2eefa557aba064e Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Tue, 14 Jan 2003 14:03:47 +0100 Subject: convert.c (strip_float_extensions): Look for narrowest type handling FP constants. * convert.c (strip_float_extensions): Look for narrowest type handling FP constants. * fold-const.c (fold): Fold (double)float1 CMP (double)float2 into float1 CMP float2. * convert.c (strip_float_extensions): Make global. * tree.h (strip_float_extensions): Declare. * gcc.dg/i386-fpcvt-1.c: New test. * gcc.dg/i386-fpcvt-2.c: New test. From-SVN: r61279 --- gcc/convert.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'gcc/convert.c') diff --git a/gcc/convert.c b/gcc/convert.c index 1ed70b5..26fb676 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -32,8 +32,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "convert.h" #include "toplev.h" #include "langhooks.h" -static tree strip_float_extensions PARAMS ((tree)); - +#include "real.h" /* Convert EXPR to some pointer or reference type TYPE. EXPR must be pointer, reference, integer, enumeral, or literal zero; @@ -75,12 +74,33 @@ convert_to_pointer (type, expr) } /* Avoid any floating point extensions from EXP. */ -static tree +tree strip_float_extensions (exp) tree exp; { tree sub, expt, subt; + /* For floating point constant look up the narrowest type that can hold + it properly and handle it like (type)(narrowest_type)constant. + This way we can optimize for instance a=a*2.0 where "a" is float + but 2.0 is double constant. */ + if (TREE_CODE (exp) == REAL_CST) + { + REAL_VALUE_TYPE orig; + tree type = NULL; + + orig = TREE_REAL_CST (exp); + if (TYPE_PRECISION (TREE_TYPE (exp)) > TYPE_PRECISION (float_type_node) + && exact_real_truncate (TYPE_MODE (float_type_node), &orig)) + type = float_type_node; + else if (TYPE_PRECISION (TREE_TYPE (exp)) + > TYPE_PRECISION (double_type_node) + && exact_real_truncate (TYPE_MODE (double_type_node), &orig)) + type = double_type_node; + if (type) + return build_real (type, real_value_truncate (TYPE_MODE (type), orig)); + } + if (TREE_CODE (exp) != NOP_EXPR) return exp; -- cgit v1.1