Commit 01d8c00b by Fariborz Jahanian Committed by Fariborz Jahanian

re PR tree-optimization/17892 (gcc-4.0 should not reassociate floating point add or multiplication)

PR 17892.
OKed by Roger Sayle.

From-SVN: r88950
parent 967af719
2004-10-12 Fariborz Jahanian <fjahanian@apple.com>
PR 17892
* tree-ssa-dom.c (unsafe_associative_fp_binop): New function.
(simplify_rhs_and_lookup_avail_expr): Disallow associativity
and constant folding of floating point MULT_EXPR/PLUS_EXPR
expressions.
2004-10-12 Ulrich Weigand <uweigand@de.ibm.com> 2004-10-12 Ulrich Weigand <uweigand@de.ibm.com>
* config/s390/s390.c (s390_va_start): Use build_va_arg_indirect_ref. * config/s390/s390.c (s390_va_start): Use build_va_arg_indirect_ref.
......
#include <float.h>
extern void abort(void);
static const double C = DBL_MAX;
double foo(double x)
{
return ( ( (x * C) * C ) * C);
}
int main ()
{
double d = foo (0.0);
if (d != 0.0)
abort ();
return 0;
}
...@@ -1634,12 +1634,20 @@ find_replaceable_in_bb (temp_expr_table_p tab, basic_block bb) ...@@ -1634,12 +1634,20 @@ find_replaceable_in_bb (temp_expr_table_p tab, basic_block bb)
var_map map = tab->map; var_map map = tab->map;
value_expr_p p; value_expr_p p;
ssa_op_iter iter; ssa_op_iter iter;
bitmap_iterator bi;
for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi)) for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
{ {
stmt = bsi_stmt (bsi); stmt = bsi_stmt (bsi);
ann = stmt_ann (stmt); ann = stmt_ann (stmt);
if (TREE_CODE (stmt) == ASM_EXPR && ASM_VOLATILE_P (stmt))
{
/* Volatile ASM_EXPRs kill all current expressions. */
EXECUTE_IF_SET_IN_BITMAP ((tab->partition_in_use), 0, partition, bi)
kill_expr (tab, partition, false);
continue;
}
/* Determine if this stmt finishes an existing expression. */ /* Determine if this stmt finishes an existing expression. */
FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_USE) FOR_EACH_SSA_TREE_OPERAND (def, stmt, iter, SSA_OP_USE)
{ {
......
...@@ -266,6 +266,7 @@ static void restore_currdefs_to_original_value (void); ...@@ -266,6 +266,7 @@ static void restore_currdefs_to_original_value (void);
static void register_definitions_for_stmt (tree); static void register_definitions_for_stmt (tree);
static edge single_incoming_edge_ignoring_loop_edges (basic_block); static edge single_incoming_edge_ignoring_loop_edges (basic_block);
static void restore_nonzero_vars_to_original_value (void); static void restore_nonzero_vars_to_original_value (void);
static inline bool unsafe_associative_fp_binop (tree);
/* Local version of fold that doesn't introduce cruft. */ /* Local version of fold that doesn't introduce cruft. */
...@@ -1549,6 +1550,18 @@ record_equality (tree x, tree y) ...@@ -1549,6 +1550,18 @@ record_equality (tree x, tree y)
record_const_or_copy_1 (x, y, prev_x); record_const_or_copy_1 (x, y, prev_x);
} }
/* Return true, if it is ok to do folding of an associative expression.
EXP is the tree for the associative expression. */
static inline bool
unsafe_associative_fp_binop (tree exp)
{
enum tree_code code = TREE_CODE (exp);
return !(!flag_unsafe_math_optimizations
&& (code == MULT_EXPR || code == PLUS_EXPR)
&& FLOAT_TYPE_P (TREE_TYPE (exp)));
}
/* STMT is a MODIFY_EXPR for which we were unable to find RHS in the /* STMT is a MODIFY_EXPR for which we were unable to find RHS in the
hash tables. Try to simplify the RHS using whatever equivalences hash tables. Try to simplify the RHS using whatever equivalences
we may have recorded. we may have recorded.
...@@ -1608,7 +1621,7 @@ simplify_rhs_and_lookup_avail_expr (struct dom_walk_data *walk_data, ...@@ -1608,7 +1621,7 @@ simplify_rhs_and_lookup_avail_expr (struct dom_walk_data *walk_data,
tree rhs_def_rhs = TREE_OPERAND (rhs_def_stmt, 1); tree rhs_def_rhs = TREE_OPERAND (rhs_def_stmt, 1);
enum tree_code rhs_def_code = TREE_CODE (rhs_def_rhs); enum tree_code rhs_def_code = TREE_CODE (rhs_def_rhs);
if (rhs_code == rhs_def_code if ((rhs_code == rhs_def_code && unsafe_associative_fp_binop (rhs))
|| (rhs_code == PLUS_EXPR && rhs_def_code == MINUS_EXPR) || (rhs_code == PLUS_EXPR && rhs_def_code == MINUS_EXPR)
|| (rhs_code == MINUS_EXPR && rhs_def_code == PLUS_EXPR)) || (rhs_code == MINUS_EXPR && rhs_def_code == PLUS_EXPR))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment