From 2cd360b676114938f74bfae8da993a67a25c9929 Mon Sep 17 00:00:00 2001 From: uros Date: Mon, 18 Jun 2007 08:30:47 +0000 Subject: [PATCH] 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. 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 | 16 ++++++++++++++++ gcc/config/i386/i386.c | 34 ++++++++++++++++++++++------------ gcc/doc/tm.texi | 13 +++++++------ gcc/target.h | 2 +- gcc/targhooks.c | 1 + gcc/targhooks.h | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/opt/pr32383.C | 20 ++++++++++++++++++++ gcc/tree-ssa-math-opts.c | 21 ++++++++++++++++++--- 9 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr32383.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4181672c8c6..490bf2ebb39 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2007-06-18 Uros Bizjak + + 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 * bt-load.c (move_btr_def): Fix the order of arguments diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 014ed0374ca..ef3d7b3b5aa 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -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 diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index cd7ae6bdfae..6e10dd28f2a 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -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) diff --git a/gcc/target.h b/gcc/target.h index 2d446a121dc..7e144dec19a 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -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 diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 620c7ec7e51..862cd6f31b8 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -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; diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 81b0eca3a4e..412bf5de804 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 96f6ff32d5f..845cd6b5a3e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-18 Uros Bizjak + + PR tree-optimization/32383 + * testsuite/g++.dg/opt/pr32383.C: New test. + 2007-06-17 Uros Bizjak 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 index 00000000000..af4161888ec --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr32383.C @@ -0,0 +1,20 @@ +// Testcase by Volker Reichelt + +// { 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); +} + diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 0534dcf2f90..0320ac1f4d4 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -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 -- 2.11.0