[PATCH] Fix -frounding-math builtins

Richard Guenther rguenther@suse.de
Mon Oct 1 13:40:00 GMT 2012


I noticed that we attach the no-vops attribute to -frounding-math
math functions.  That's bogus as can be seen from the testcase

int fesetround(int);
double asinh(double x);

double foo (double x, int b)
{
  double y = 0.0, z;
  if (b)
    y = asinh (x);
  fesetround (0x400 /*FE_DOWNWARD*/);
  z = asinh (x);
  return y + z;
}

where PRE rightfully so removes a seeming partial redundancy by
inserting a asinh call into the else block.  That's because
it exactly does _not_ get to see the rounding mode clobbering
fesetround call as asinh does not have a virtual operand.

Fixed as follows.

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

Richard.

2012-10-01  Richard Guenther  <rguenther@suse.de>

	* builtins.def (ATTR_MATHFN_FPROUNDING): Do not use no-vops
	with -frounding-math.
	* builtin-attrs.def (ATTR_PURE_NOTHROW_NOVOPS_LIST): Remove.
	(ATTR_PURE_NOTHROW_NOVOPS_LEAF_LIST): Likewise.

Index: gcc/builtins.def
===================================================================
*** gcc/builtins.def	(revision 191917)
--- gcc/builtins.def	(working copy)
*************** along with GCC; see the file COPYING3.
*** 163,169 ****
     memory.  */
  #undef ATTR_MATHFN_FPROUNDING
  #define ATTR_MATHFN_FPROUNDING (flag_rounding_math ? \
! 	ATTR_PURE_NOTHROW_NOVOPS_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST)
  
  /* Define an attribute list for math functions that are normally
     "impure" because some of them may write into global memory for
--- 163,169 ----
     memory.  */
  #undef ATTR_MATHFN_FPROUNDING
  #define ATTR_MATHFN_FPROUNDING (flag_rounding_math ? \
! 	ATTR_PURE_NOTHROW_LEAF_LIST : ATTR_CONST_NOTHROW_LEAF_LIST)
  
  /* Define an attribute list for math functions that are normally
     "impure" because some of them may write into global memory for
Index: gcc/builtin-attrs.def
===================================================================
*** gcc/builtin-attrs.def	(revision 191917)
--- gcc/builtin-attrs.def	(working copy)
*************** DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LI
*** 127,136 ****
  			ATTR_NULL, ATTR_NOTHROW_LIST)
  DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LEAF_LIST, ATTR_PURE,	\
  			ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
- DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NOVOPS_LIST, ATTR_NOVOPS,	\
- 			ATTR_NULL, ATTR_PURE_NOTHROW_LIST)
- DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_NOVOPS_LEAF_LIST, ATTR_NOVOPS,\
- 			ATTR_NULL, ATTR_PURE_NOTHROW_LEAF_LIST)
  DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN,	\
  			ATTR_NULL, ATTR_NOTHROW_LIST)
  DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\
--- 127,132 ----



More information about the Gcc-patches mailing list