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]

Simplify FP conversions in convert


Hi,
this patch makes the symetric change to convert.c
Bootstrapped/regtested on i386 together with the other patches.  OK?

Honza

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	9 Feb 2003 18:02:49 -0000
*************** convert_to_real (type, expr)
*** 204,209 ****
--- 204,242 ----
    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.  */
+ 		    || ((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 */
+ 		&& (TYPE_PRECISION (TREE_TYPE (expr))
+ 		    > TYPE_PRECISION (TREE_TYPE (op))
+ 		   /* (double)(float)short == (double)short.
+ 		      Must ensure that the source fits in the type.  */
+ 		    || (TYPE_PRECISION (type)
+ 		        >= 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:


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