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]

[PATCH] Fix PR28473, wrong-code folding (unsigned long long)round()


This fixes PR28473 by also checking for unsigned long long types.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline and branches?

Thanks,
Richard.

2006-07-25  Richard Guenther  <rguenther@suse.de>

	PR middle-end/28473
	* convert.c (convert_to_integer): Handle unsigned types
	in folding (T)round(x) to {l,ll}round(x) and friends.

	* gcc.dg/builtins-54.c: New testcase.

Index: convert.c
===================================================================
*** convert.c	(revision 115715)
--- convert.c	(working copy)
*************** convert_to_integer (tree type, tree expr
*** 355,361 ****
  	  /* Only convert in ISO C99 mode.  */
  	  if (!TARGET_C99_FUNCTIONS)
  	    break;
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL);
--- 355,362 ----
  	  /* Only convert in ISO C99 mode.  */
  	  if (!TARGET_C99_FUNCTIONS)
  	    break;
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)
! 	      || TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_unsigned_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL);
*************** convert_to_integer (tree type, tree expr
*** 365,378 ****
  	  /* Only convert in ISO C99 mode.  */
  	  if (!TARGET_C99_FUNCTIONS)
  	    break;
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LFLOOR);
  	  break;
  
  	case BUILT_IN_ROUND: case BUILT_IN_ROUNDF: case BUILT_IN_ROUNDL:
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LROUND);
--- 366,381 ----
  	  /* Only convert in ISO C99 mode.  */
  	  if (!TARGET_C99_FUNCTIONS)
  	    break;
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)
! 	      || TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_unsigned_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LFLOOR);
  	  break;
  
  	case BUILT_IN_ROUND: case BUILT_IN_ROUNDF: case BUILT_IN_ROUNDL:
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)
! 	      || TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_unsigned_type_node))
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND);
  	  else
  	    fn = mathfn_built_in (s_intype, BUILT_IN_LROUND);
*************** convert_to_integer (tree type, tree expr
*** 384,390 ****
  	    break;
  	  /* ... Fall through ...  */
  	case BUILT_IN_NEARBYINT: case BUILT_IN_NEARBYINTF: case BUILT_IN_NEARBYINTL:
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node))
              fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT);
  	  else
              fn = mathfn_built_in (s_intype, BUILT_IN_LRINT);
--- 387,394 ----
  	    break;
  	  /* ... Fall through ...  */
  	case BUILT_IN_NEARBYINT: case BUILT_IN_NEARBYINTF: case BUILT_IN_NEARBYINTL:
! 	  if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)
! 	      || TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_unsigned_type_node))
              fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT);
  	  else
              fn = mathfn_built_in (s_intype, BUILT_IN_LRINT);
Index: testsuite/gcc.dg/builtins-54.c
===================================================================
*** testsuite/gcc.dg/builtins-54.c	(revision 0)
--- testsuite/gcc.dg/builtins-54.c	(revision 0)
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-original" } */
+ 
+ unsigned long long foo(unsigned long long x)
+ {
+      return (unsigned long long)__builtin_round(x);
+ }
+ 
+ /* { dg-final { scan-tree-dump "llround" "original" } } */
+ /* { dg-final { cleanup-tree-dump "original" } } */


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