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
This commit is contained in:
parent
a8d8890adb
commit
ac10986fad
9 changed files with 91 additions and 23 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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
|
||||
|
|
20
gcc/testsuite/g++.dg/opt/pr32383.C
Normal file
20
gcc/testsuite/g++.dg/opt/pr32383.C
Normal file
|
@ -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);
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue