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, middle-end]: Optimize a/sqrt(b/c) into a*sqrt(c/b).


Hello!

This patch optimizes a/sqrt(b/c) into a*sqrt(c/b), converting one division into the multiplication. This patch also converts cases like sqrt(a)/sqrt(1.0/b) into sqrt (b*a).

Patch was bootstrapped on x86_64-pc-linux-gnu, regression test for all default languages is in progress. OK for mainline if it passes?

2007-06-11 Uros Bizjak <ubizjak@gmail.com>

       * fold-const (fold_binary) [RDIV_EXPR]: Optimize a/sqrt(b/c)
       into a*sqrt(c/b) if flag_unsafe_math_optimizations is set.

Uros.
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 125605)
+++ fold-const.c	(working copy)
@@ -10555,6 +10555,24 @@ fold_binary (enum tree_code code, tree t
 		}
 	    }
 
+	  /* Optimize a/sqrt(b/c) into a*sqrt(c/b).  */
+	  if (BUILTIN_SQRT_P (fcode1))
+	    {
+	      tree rootarg = CALL_EXPR_ARG (arg1, 0);
+
+	      if (TREE_CODE (rootarg) == RDIV_EXPR)
+		{
+		  tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
+		  tree b = TREE_OPERAND (rootarg, 0);
+		  tree c = TREE_OPERAND (rootarg, 1);
+
+		  tree tmp = fold_build2 (RDIV_EXPR, type, c, b);
+
+		  tmp = build_call_expr (rootfn, 1, tmp);
+		  return fold_build2 (MULT_EXPR, type, arg0, tmp);
+		}
+	    }
+	     
 	  /* Optimize x/expN(y) into x*expN(-y).  */
 	  if (BUILTIN_EXPONENT_P (fcode1))
 	    {

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