aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2007-06-18 10:30:47 +0200
committerUros Bizjak <uros@gcc.gnu.org>2007-06-18 10:30:47 +0200
commitac10986fadc255c27db122daa244f8f71c5462f2 (patch)
treea70a489abddc4e7f99e532e8ae5b8057df6f9b21 /gcc
parenta8d8890adb3be434ee6eec4f104f322e6c247c5a (diff)
downloadgcc-ac10986fadc255c27db122daa244f8f71c5462f2.zip
gcc-ac10986fadc255c27db122daa244f8f71c5462f2.tar.gz
gcc-ac10986fadc255c27db122daa244f8f71c5462f2.tar.bz2
re PR tree-optimization/32383 (ICE with reciprocals and -ffast-math)
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. From-SVN: r125790
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog16
-rw-r--r--gcc/config/i386/i386.c34
-rw-r--r--gcc/doc/tm.texi13
-rw-r--r--gcc/target.h2
-rw-r--r--gcc/targhooks.c1
-rw-r--r--gcc/targhooks.h2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/opt/pr32383.C20
-rw-r--r--gcc/tree-ssa-math-opts.c21
9 files changed, 91 insertions, 23 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4181672c..490bf2e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 014ed03..ef3d7b3 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 cd7ae6b..6e10dd2 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 2d446a1..7e144de 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 620c7ec..862cd6f 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 81b0eca..412bf5d 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 96f6ff3..845cd6b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..af41618
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr32383.C
@@ -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);
+}
+
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index 0534dcf..0320ac1 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