Patchwork Fix PR50195

login
register
mail settings
Submitter Richard Guenther
Date Oct. 10, 2011, 2:23 p.m.
Message ID <alpine.LNX.2.00.1110101622370.2130@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/118743/
State New
Headers show

Comments

Richard Guenther - Oct. 10, 2011, 2:23 p.m.
Canonicalize x*x to pow(x,2) only when optimizing which is when
we do optimized expansion.

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

Richard.

2011-10-10  Richard Guenther  <rguenther@suse.de>

	PR middle-end/50195
	* fold-const.c (fold_binary_loc): Canonicalize x*x to pow (x, 2)
	only when optimizing.

	* gcc.dg/builtins-47.c: Optimize.

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 179738)
+++ gcc/fold-const.c	(working copy)
@@ -10693,9 +10693,9 @@  fold_binary_loc (location_t loc,
 		    }
 		}
 
-	      /* Optimize x*x as pow(x,2.0), which is expanded as x*x.  */
+	      /* Canonicalize x*x as pow(x,2.0), which is expanded as x*x.  */
 	      if (!in_gimple_form
-		  && optimize_function_for_speed_p (cfun)
+		  && optimize
 		  && operand_equal_p (arg0, arg1, 0))
 		{
 		  tree powfn = mathfn_built_in (type, BUILT_IN_POW);
Index: gcc/testsuite/gcc.dg/builtins-47.c
===================================================================
--- gcc/testsuite/gcc.dg/builtins-47.c	(revision 179738)
+++ gcc/testsuite/gcc.dg/builtins-47.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* { dg-do run } */
-/* { dg-options "-ffast-math -fdump-tree-gimple" } */
+/* { dg-options "-O -ffast-math -fdump-tree-gimple" } */
 
 extern double sqrt (double);
 extern double pow (double, double);