This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix dom fp folding error
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Jul 2004 11:59:59 -0700
- Subject: fix dom fp folding error
This fixes the standard implementation of rint, which is to add
and subtract b**p.
r~
* tree-ssa-dom.c (simplify_rhs_and_lookup_avail_expr): Don't fold
fp plus with minus.
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.21
diff -c -p -d -r2.21 tree-ssa-dom.c
*** tree-ssa-dom.c 3 Jul 2004 13:45:29 -0000 2.21
--- tree-ssa-dom.c 3 Jul 2004 18:51:17 -0000
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1945,1950 ****
--- 1945,1969 ----
tree type = TREE_TYPE (TREE_OPERAND (stmt, 0));
tree t;
+ /* If we care about correct floating point results, then
+ don't fold x + c1 - c2. Note that we need to take both
+ the codes and the signs to figure this out. */
+ if (FLOAT_TYPE_P (type)
+ && !flag_unsafe_math_optimizations
+ && (rhs_def_code == PLUS_EXPR
+ || rhs_def_code == MINUS_EXPR))
+ {
+ bool neg = false;
+
+ neg ^= (rhs_code == MINUS_EXPR);
+ neg ^= (rhs_def_code == MINUS_EXPR);
+ neg ^= real_isneg (TREE_REAL_CST_PTR (outer_const));
+ neg ^= real_isneg (TREE_REAL_CST_PTR (def_stmt_op1));
+
+ if (neg)
+ goto dont_fold_assoc;
+ }
+
/* Ho hum. So fold will only operate on the outermost
thingy that we give it, so we have to build the new
expression in two pieces. This requires that we handle
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1979,1984 ****
--- 1998,2004 ----
}
}
}
+ dont_fold_assoc:;
}
/* Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR
Index: testsuite/gcc.dg/tree-ssa/20040703-1.c
===================================================================
RCS file: testsuite/gcc.dg/tree-ssa/20040703-1.c
diff -N testsuite/gcc.dg/tree-ssa/20040703-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tree-ssa/20040703-1.c 3 Jul 2004 18:51:17 -0000
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fdump-tree-dom2" } */
+
+ float foo(float x)
+ {
+ x += 1;
+ x -= 1;
+ return x;
+ }
+
+ /* We should *not* fold the arithmetic. */
+ /* { dg-final { scan-tree-dump-times "0.0" 0 "dom2"} } */