[PATCH] Constant fold sqrt at compile time (take 2)

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sun Nov 3 06:11:00 GMT 2002


 > !	      /* Optimize sqrt(0.0) = 0.0 and sqrt(1.0) = 1.0.  */
 > !	        if (real_zerop (arg) || real_onep (arg))
 > !		    return arg;
 > 
 > 		      /* Optimize sqrt(exp(x)) = exp(x/2.0).  */
 > 		        fcode = builtin_mathfn_code (arg);
 > --- 4241,4260 ----
 >       enum built_in_function fcode;
 >         tree arg = TREE_VALUE (arglist);
 > 
 > !	  /* Optimize sqrt of constant value.  */
 > !	    if (flag_unsafe_math_optimizations
 > !	          && TREE_CODE (arg) == REAL_CST
 > !		        && ! TREE_CONSTANT_OVERFLOW (arg))


Minor nit:

Since 0.0 and 1.0 are always safe to optimize, rather than delete
them IMO you should do this:

if (0.0 || 1.0)
  return arg;
else if (flag_unsafe_math_optimizations ...

Only kill 0.0 & 1.0 if and when you get this working without
flag_unsafe_math_optimizations.

		--Kaveh
--
Kaveh R. Ghazi			ghazi@caip.rutgers.edu



More information about the Gcc-patches mailing list