This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Updated patch for FP conversions part 1


Hi,
this patch is updated version of the patch to simplify FP conversions that
handles only arithmetics now.  This is because after the discussion concerning
floor and friends I realized that I can't implicitly creat *f/*l functions in
C90 mode since runtime is not required to support them.  I will add some
infrastructure for that first and the send updated patch of the second part.

Bootstrapped/regtested i386, OK for BIB branch?

Honza

Sat Nov  9 18:32:29 CET 2002  Jan Hubicka  <jh@suse.cz>
	* convert.c (strip_float_extensions): New function.
	(convert_to_real): Simplify some cases.
Index: convert.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/convert.c,v
retrieving revision 1.19
diff -c -3 -p -r1.19 convert.c
*** convert.c	4 Jul 2002 06:38:54 -0000	1.19
--- convert.c	9 Nov 2002 17:32:01 -0000
*************** Software Foundation, 59 Temple Place - S
*** 30,35 ****
--- 30,36 ----
  #include "convert.h"
  #include "toplev.h"
  #include "langhooks.h"
+ static tree strip_float_extensions PARAMS ((tree));
  
  /* Convert EXPR to some pointer or reference type TYPE.
  
*************** convert_to_pointer (type, expr)
*** 71,76 ****
--- 72,101 ----
      }
  }
  
+ /* Avoid any floating point extensions from EXP.  */
+ static tree
+ strip_float_extensions (exp)
+      tree exp;
+ {
+   tree sub, expt, subt;
+ 
+   if (TREE_CODE (exp) != NOP_EXPR)
+     return exp;
+ 
+   sub = TREE_OPERAND (exp, 0);
+   subt = TREE_TYPE (sub);
+   expt = TREE_TYPE (exp);
+ 
+   if (!FLOAT_TYPE_P (subt))
+     return exp;
+ 
+   if (TYPE_PRECISION (subt) > TYPE_PRECISION (expt))
+     return exp;
+ 
+   return strip_float_extensions (sub);
+ }
+ 
+ 
  /* Convert EXPR to some floating-point type TYPE.
  
     EXPR must be float, integer, or enumeral;
*************** tree
*** 80,85 ****
--- 105,157 ----
  convert_to_real (type, expr)
       tree type, expr;
  {
+   enum built_in_function fcode = builtin_mathfn_code (expr);
+   tree itype = TREE_TYPE (expr);
+ 
+   /* Propagate the cast into the operation.  */
+   if (optimize && itype != type && FLOAT_TYPE_P (type))
+     switch (TREE_CODE (expr))
+       {
+ 	/* convert (float)-x into -(float)x.  This is always safe.  */
+ 	case ABS_EXPR:
+ 	case NEGATE_EXPR:
+ 	  return build1 (TREE_CODE (expr), type,
+ 			 fold (convert_to_real (type,
+ 						TREE_OPERAND (expr, 0))));
+ 	/* convert (outertype)((innertype0)a+(innertype1)b)
+ 	   into ((newtype)a+(newtype)b) where newtype
+ 	   is the widest mode from all of these.  */
+ 	case PLUS_EXPR:
+ 	case MINUS_EXPR:
+ 	case MULT_EXPR:
+ 	case RDIV_EXPR:
+ 	   {
+ 	     tree arg0 = strip_float_extensions (TREE_OPERAND (expr, 0));
+ 	     tree arg1 = strip_float_extensions (TREE_OPERAND (expr, 1));
+ 
+ 	     if (FLOAT_TYPE_P (TREE_TYPE (arg0))
+ 		 && FLOAT_TYPE_P (TREE_TYPE (arg1)))
+ 	       {
+ 		  tree newtype = type;
+ 		  if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (newtype))
+ 		    newtype = TREE_TYPE (arg0);
+ 		  if (TYPE_PRECISION (TREE_TYPE (arg1)) > TYPE_PRECISION (newtype))
+ 		    newtype = TREE_TYPE (arg1);
+ 		  if (TYPE_PRECISION (newtype) < TYPE_PRECISION (itype))
+ 		    {
+ 		      expr = build (TREE_CODE (expr), newtype,
+ 				    fold (convert_to_real (newtype, arg0)),
+ 				    fold (convert_to_real (newtype, arg1)));
+ 		      if (newtype == type)
+ 			return expr;
+ 		    }
+ 	       }
+ 	   }
+ 	  break;
+ 	default:
+ 	  break;
+       }
+ 
    switch (TREE_CODE (TREE_TYPE (expr)))
      {
      case REAL_TYPE:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]