[PATCH] Constant fold fabs(x)*fabs(x) as x*x

Bernd Schmidt bernds_cb1@t-online.de
Wed Feb 9 21:49:00 GMT 2005


> 	* fold-const.c (fold_strip_sign_ops): New function to simplify a
> 	floating point expression ignoring the sign of the result.
> 	(fold) <ABS_EXPR>: Use it to simplify fabs(x).
> 	(fold) <MULT_EXPR>: Use it to simplify x*x.
> 	* tree.h (fold_strip_sign_ops): Prototype here.
> 	* builtins.c (fold_builtin_copysign): Take an additional FNDECL
> 	argument.  Use fold_strip_sign_ops to simplify the first argument.
> 	(fold_builtin_pow):  Use fold_strip_sign_ops to simplify the
> 	first argument when the second argument is an even integer
> 	constant, but only with -funsafe_math_optimizations.
> 	(fold_builtin_1): Update call to fold_builtin_copysign.
> 
> 	* gcc.dg/builtins-48.c: New test case.
> 	* gcc.dg/builtins-49.c: New test case.
> 	* gcc.dg/builtins-50.c: New test case.
> 	* gcc.dg/builtins-51.c: New test case.

Looks ok, but...

> + 		  arglist = tree_cons (NULL_TREE, narg0, TREE_CHAIN (arglist));
> + 		  return build_function_call_expr (fndecl, arglist);
> + 		}

... I'm not familiar enough with trees to be sure whether this kind of 
sharing could be problematic.  Other places in the same file use

     arglist = build_tree_list (NULL_TREE,
                                TREE_VALUE (TREE_CHAIN (arglist)));

in similar situations, so maybe that's a precedent we should follow.


Bernd



More information about the Gcc-patches mailing list