public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Move strip_float_extensions to tree.c
@ 2012-03-07 12:46 Richard Guenther
  2012-03-07 18:55 ` Joseph S. Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Guenther @ 2012-03-07 12:46 UTC (permalink / raw)
  To: gcc-patches


Prototyped in tree.h, called from the middle-end but implemented
in convert.c.  That looks wrong.

Now, convert.c is used from all frontends to implement convert ()
(that looks backwards - the language convert should be a langhook,
called from convert implemented in convert.c).  But well, I aint
not touching this beast ;)

At least with this patch convert.c functions are all convert_to_*,
only called directly by frontends (while they should be all
static to convert.c, called from convert () only(?)).

Queued for bootstrap / regtest.

Richard.

2012-03-07  Richard Guenther  <rguenther@suse.de>

	* convert.c (strip_float_extensions): Move ...
	* tree.c (strip_float_extensions): ... here.

Index: gcc/convert.c
===================================================================
*** gcc/convert.c	(revision 185029)
--- gcc/convert.c	(working copy)
*************** convert_to_pointer (tree type, tree expr
*** 90,141 ****
      }
  }
  
- /* Avoid any floating point extensions from EXP.  */
- tree
- strip_float_extensions (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 && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
-     {
-       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 (!CONVERT_EXPR_P (exp))
-     return exp;
- 
-   sub = TREE_OPERAND (exp, 0);
-   subt = TREE_TYPE (sub);
-   expt = TREE_TYPE (exp);
- 
-   if (!FLOAT_TYPE_P (subt))
-     return exp;
- 
-   if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_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.
  
--- 90,95 ----
Index: gcc/tree.c
===================================================================
*** gcc/tree.c	(revision 185029)
--- gcc/tree.c	(working copy)
*************** tree_strip_sign_nop_conversions (tree ex
*** 11213,11218 ****
--- 11209,11260 ----
    return exp;
  }
  
+ /* Avoid any floating point extensions from EXP.  */
+ tree
+ strip_float_extensions (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 && !DECIMAL_FLOAT_TYPE_P (TREE_TYPE (exp)))
+     {
+       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 (!CONVERT_EXPR_P (exp))
+     return exp;
+ 
+   sub = TREE_OPERAND (exp, 0);
+   subt = TREE_TYPE (sub);
+   expt = TREE_TYPE (exp);
+ 
+   if (!FLOAT_TYPE_P (subt))
+     return exp;
+ 
+   if (DECIMAL_FLOAT_TYPE_P (expt) != DECIMAL_FLOAT_TYPE_P (subt))
+     return exp;
+ 
+   if (TYPE_PRECISION (subt) > TYPE_PRECISION (expt))
+     return exp;
+ 
+   return strip_float_extensions (sub);
+ }
+ 
  /* Strip out all handled components that produce invariant
     offsets.  */
  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Move strip_float_extensions to tree.c
  2012-03-07 12:46 [PATCH] Move strip_float_extensions to tree.c Richard Guenther
@ 2012-03-07 18:55 ` Joseph S. Myers
  2012-03-12  9:03   ` Richard Guenther
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph S. Myers @ 2012-03-07 18:55 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc-patches

On Wed, 7 Mar 2012, Richard Guenther wrote:

> Now, convert.c is used from all frontends to implement convert ()
> (that looks backwards - the language convert should be a langhook,
> called from convert implemented in convert.c).  But well, I aint
> not touching this beast ;)

I don't think convert () should be a langhook; it's all about 
language-specific semantics (the only non-front-end places calling it, 
outside of convert.c itself, now appear to be in arm.c).

I'm not sure of the extent to which the recursive calls to convert inside 
convert.c need any language-specific semantics.  To the extent that they 
do, I think front ends should be dealing with the semantics rather than 
having convert call back into the front end.  (I also think all the errors 
from convert.c should be given by front ends instead; front ends should 
only call the convert_to_* helpers for code they have checked is valid.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Move strip_float_extensions to tree.c
  2012-03-07 18:55 ` Joseph S. Myers
@ 2012-03-12  9:03   ` Richard Guenther
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Guenther @ 2012-03-12  9:03 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

On Wed, 7 Mar 2012, Joseph S. Myers wrote:

> On Wed, 7 Mar 2012, Richard Guenther wrote:
> 
> > Now, convert.c is used from all frontends to implement convert ()
> > (that looks backwards - the language convert should be a langhook,
> > called from convert implemented in convert.c).  But well, I aint
> > not touching this beast ;)
> 
> I don't think convert () should be a langhook; it's all about 
> language-specific semantics (the only non-front-end places calling it, 
> outside of convert.c itself, now appear to be in arm.c).
>
> I'm not sure of the extent to which the recursive calls to convert inside 
> convert.c need any language-specific semantics.  To the extent that they 
> do, I think front ends should be dealing with the semantics rather than 
> having convert call back into the front end.  (I also think all the errors 
> from convert.c should be given by front ends instead; front ends should 
> only call the convert_to_* helpers for code they have checked is valid.)

I was thinking about having convert () be a middle-end function
(not langhook) working on generic, that does all frontend specific
stuff via a langhook (I didn't try to compare the convert implementations
to see if there is even any language-specifics about them).

I agree that errors should be raised from the frontends (also the
remaining optimizations convert_to_* do should be either moved to
fold or to later gimple optimization passes).

But no, I'm not going to touch this - maybe apart from removing
the obvious wrong users in arm.c.

Richard.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-03-12  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 12:46 [PATCH] Move strip_float_extensions to tree.c Richard Guenther
2012-03-07 18:55 ` Joseph S. Myers
2012-03-12  9:03   ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).