OSDN Git Service

PR tree-optimization/32383
authoruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Jun 2007 08:30:47 +0000 (08:30 +0000)
committeruros <uros@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Jun 2007 08:30:47 +0000 (08:30 +0000)
* targhooks.c (default_builtin_reciprocal): Add new bool argument.
* targhooks.h (default_builtin_reciprocal): Update prototype.
* target.h (struct gcc_target): Update builtin_reciprocal.
* doc/tm.texi (TARGET_BUILTIN_RECIPROCAL): Update description.
* tree-ssa-math-opts (execute_cse_reciprocals): Skip statements
where arg1 is not SSA_NAME.  Pass true to targetm.builtin_reciprocal
when fndecl is in BUILT_IN_MD class.
(execute_convert_to_rsqrt): Ditto.

* config/i386/i386.c (ix86_builtin_reciprocal): Update for new bool
argument.  Convert IX86_BUILTIN_SQRTPS code only when md_fn is true.
Convert BUILT_IN_SQRTF code only  when md_fn is false.

testsuite/ChangeLog:

PR tree-optimization/32383
* testsuite/g++.dg/opt/pr32383.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@125790 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/doc/tm.texi
gcc/target.h
gcc/targhooks.c
gcc/targhooks.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr32383.C [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index 4181672..490bf2e 100644 (file)
@@ -1,3 +1,19 @@
+2007-06-18  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR tree-optimization/32383
+       * targhooks.c (default_builtin_reciprocal): Add new bool argument.
+       * targhooks.h (default_builtin_reciprocal): Update prototype.
+       * target.h (struct gcc_target): Update builtin_reciprocal.
+       * doc/tm.texi (TARGET_BUILTIN_RECIPROCAL): Update description.
+       * tree-ssa-math-opts (execute_cse_reciprocals): Skip statements
+       where arg1 is not SSA_NAME.  Pass true to targetm.builtin_reciprocal
+       when fndecl is in BUILT_IN_MD class.
+       (execute_convert_to_rsqrt): Ditto.
+
+       * config/i386/i386.c (ix86_builtin_reciprocal): Update for new bool
+       argument.  Convert IX86_BUILTIN_SQRTPS code only when md_fn is true.
+       Convert BUILT_IN_SQRTF code only  when md_fn is false.
+
 2007-06-18  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        * bt-load.c (move_btr_def): Fix the order of arguments
index 014ed03..ef3d7b3 100644 (file)
@@ -19911,26 +19911,36 @@ ix86_vectorize_builtin_conversion (unsigned int code, tree type)
    reciprocal of the function, or NULL_TREE if not available.  */
 
 static tree
-ix86_builtin_reciprocal (unsigned int code, bool sqrt ATTRIBUTE_UNUSED)
+ix86_builtin_reciprocal (unsigned int fn, bool md_fn,
+                        bool sqrt ATTRIBUTE_UNUSED)
 {
   if (! (TARGET_SSE_MATH && TARGET_RECIP && !optimize_size
         && flag_finite_math_only && !flag_trapping_math
         && flag_unsafe_math_optimizations))
     return NULL_TREE;
 
-  switch (code)
-    {
-    /* Sqrt to rsqrt conversion.  */
-    case BUILT_IN_SQRTF:
-      return ix86_builtins[IX86_BUILTIN_RSQRTF];
+  if (md_fn)
+    /* Machine dependent builtins.  */
+    switch (fn)
+      {
+       /* Vectorized version of sqrt to rsqrt conversion.  */
+      case IX86_BUILTIN_SQRTPS:
+       return ix86_builtins[IX86_BUILTIN_RSQRTPS];
 
-    /* Vectorized version of sqrt to rsqrt conversion.  */
-    case IX86_BUILTIN_SQRTPS:
-      return ix86_builtins[IX86_BUILTIN_RSQRTPS];
+      default:
+       return NULL_TREE;
+      }
+  else
+    /* Normal builtins.  */
+    switch (fn)
+      {
+       /* Sqrt to rsqrt conversion.  */
+      case BUILT_IN_SQRTF:
+       return ix86_builtins[IX86_BUILTIN_RSQRTF];
 
-    default:
-      return NULL_TREE;
-    }
+      default:
+       return NULL_TREE;
+      }
 }
 
 /* Store OPERAND to the memory after reload is completed.  This means
index cd7ae6b..6e10dd2 100644 (file)
@@ -5345,13 +5345,14 @@ of @var{x}.
 The default version returns false for all constants.
 @end deftypefn
 
-@deftypefn {Target Hook} tree TARGET_BUILTIN_RECIPROCAL (enum tree_code @var{code}, bool @var{sqrt})
+@deftypefn {Target Hook} tree TARGET_BUILTIN_RECIPROCAL (enum tree_code @var{fn}, bool @var{tm_fn}, bool @var{sqrt})
 This hook should return the DECL of a function that implements reciprocal of
-the builtin function with builtin function code @var{code}, or
-@code{NULL_TREE} if such a function is not available.  When @var{sqrt} is
-true, additional optimizations that apply only to the reciprocal of a square
-root function are performed, and only reciprocals of @code{sqrt} function
-are valid.
+the builtin function with builtin function code @var{fn}, or
+@code{NULL_TREE} if such a function is not available.  @var{tm_fn} is true
+when @var{fn} is a code of a machine-dependent builtin function.  When
+@var{sqrt} is true, additional optimizations that apply only to the reciprocal
+of a square root function are performed, and only reciprocals of @code{sqrt}
+function are valid.
 @end deftypefn
 
 @deftypefn {Target Hook} tree TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD (void)
index 2d446a1..7e144de 100644 (file)
@@ -485,7 +485,7 @@ struct gcc_target
 
   /* Returns a code for a target-specific builtin that implements
      reciprocal of the function, or NULL_TREE if not available.  */
-  tree (* builtin_reciprocal) (unsigned, bool);
+  tree (* builtin_reciprocal) (unsigned, bool, bool);
 
   /* For a vendor-specific fundamental TYPE, return a pointer to
      a statically-allocated string containing the C++ mangling for
index 620c7ec..862cd6f 100644 (file)
@@ -342,6 +342,7 @@ default_builtin_vectorized_conversion (enum tree_code code ATTRIBUTE_UNUSED,
 
 tree
 default_builtin_reciprocal (enum built_in_function fn ATTRIBUTE_UNUSED,
+                           bool md_fn ATTRIBUTE_UNUSED,
                            bool sqrt ATTRIBUTE_UNUSED)
 {
   return NULL_TREE;
index 81b0eca..412bf5d 100644 (file)
@@ -60,7 +60,7 @@ extern tree default_builtin_vectorized_function
 
 extern tree default_builtin_vectorized_conversion (enum tree_code, tree);
 
-extern tree default_builtin_reciprocal (enum built_in_function, bool);
+extern tree default_builtin_reciprocal (enum built_in_function, bool, bool);
 
 /* These are here, and not in hooks.[ch], because not all users of
    hooks.h include tm.h, and thus we don't have CUMULATIVE_ARGS.  */
index 96f6ff3..845cd6b 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-18  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR tree-optimization/32383
+       * testsuite/g++.dg/opt/pr32383.C: New test.
+
 2007-06-17  Uros Bizjak  <ubizjak@gmail.com>
 
        PR rtl-optimization/32366
diff --git a/gcc/testsuite/g++.dg/opt/pr32383.C b/gcc/testsuite/g++.dg/opt/pr32383.C
new file mode 100644 (file)
index 0000000..af41618
--- /dev/null
@@ -0,0 +1,20 @@
+// Testcase by Volker Reichelt <reichelt@gcc.gnu.org>
+
+// { dg-do compile }
+// { dg-options "-O -ffast-math" }
+
+struct A
+{
+  ~A();
+};
+
+double& foo();
+
+inline void bar (double d) { foo() /= d; }
+
+void baz()
+{
+  A a;
+  bar(2);
+}
+
index 0534dcf..0320ac1 100644 (file)
@@ -507,7 +507,12 @@ execute_cse_reciprocals (void)
              && TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == RDIV_EXPR)
            {
              tree arg1 = TREE_OPERAND (GIMPLE_STMT_OPERAND (stmt, 1), 1);
-             tree stmt1 = SSA_NAME_DEF_STMT (arg1);
+             tree stmt1;
+
+             if (TREE_CODE (arg1) != SSA_NAME)
+               continue;
+
+             stmt1 = SSA_NAME_DEF_STMT (arg1);
 
              if (TREE_CODE (stmt1) == GIMPLE_MODIFY_STMT
                  && TREE_CODE (GIMPLE_STMT_OPERAND (stmt1, 1)) == CALL_EXPR
@@ -517,11 +522,14 @@ execute_cse_reciprocals (void)
                      || DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD))
                {
                  enum built_in_function code;
+                 bool md_code;
                  tree arg10;
                  tree tmp;
 
                  code = DECL_FUNCTION_CODE (fndecl);
-                 fndecl = targetm.builtin_reciprocal (code, false);
+                 md_code = DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD;
+
+                 fndecl = targetm.builtin_reciprocal (code, md_code, false);
                  if (!fndecl)
                    continue;
 
@@ -791,15 +799,22 @@ execute_convert_to_rsqrt (void)
                  || DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD))
            {
              enum built_in_function code;
+             bool md_code;
              tree arg1;
              tree stmt1;
 
              code = DECL_FUNCTION_CODE (fndecl);
-             fndecl = targetm.builtin_reciprocal (code, true);
+             md_code = DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD;
+
+             fndecl = targetm.builtin_reciprocal (code, md_code, true);
              if (!fndecl)
                continue;
 
              arg1 = CALL_EXPR_ARG (GIMPLE_STMT_OPERAND (stmt, 1), 0);
+
+             if (TREE_CODE (arg1) != SSA_NAME)
+               continue;
+
              stmt1 = SSA_NAME_DEF_STMT (arg1);
 
              if (TREE_CODE (stmt1) == GIMPLE_MODIFY_STMT