OSDN Git Service

* tree-ssa-dom.c (simplify_rhs_and_lookup_avail_expr): Don't fold
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 3 Jul 2004 18:57:18 +0000 (18:57 +0000)
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 3 Jul 2004 18:57:18 +0000 (18:57 +0000)
        fp plus with minus.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84061 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c [new file with mode: 0644]
gcc/tree-ssa-dom.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c b/gcc/testsuite/gcc.dg/tree-ssa/20040703-1.c
new file mode 100644 (file)
index 0000000..8f6ae16
--- /dev/null
@@ -0,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"} } */
index b556b4e..356daac 100644 (file)
@@ -1945,6 +1945,25 @@ simplify_rhs_and_lookup_avail_expr (struct dom_walk_data *walk_data,
                  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
@@ -1979,6 +1998,7 @@ simplify_rhs_and_lookup_avail_expr (struct dom_walk_data *walk_data,
                }
            }
        }
+ dont_fold_assoc:;
     }
 
   /* Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR