OSDN Git Service

gcc/
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 13 Sep 2008 15:47:41 +0000 (15:47 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 13 Sep 2008 15:47:41 +0000 (15:47 +0000)
2008-09-13  H.J. Lu  <hongjiu.lu@intel.com>

PR rtl-optimization/37489
* cse.c (fold_rtx): Don't return const_true_rtx for float
compare if FLOAT_STORE_FLAG_VALUE is undefined.

gcc/testsuite/

2008-09-13  Raksit Ashok <raksit@google.com>

PR rtl-optimization/37489
* g++.dg/opt/cse3.C: New.

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

gcc/ChangeLog
gcc/cse.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/cse3.C [new file with mode: 0644]

index 1f07ada..7375041 100644 (file)
@@ -1,3 +1,9 @@
+2008-09-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR rtl-optimization/37489
+       * cse.c (fold_rtx): Don't return const_true_rtx for float
+       compare if FLOAT_STORE_FLAG_VALUE is undefined.
+
 2008-09-13  Jan Hubicka  <jh@suse.cz>
 
        PR tree-optimization/37392
index c1effee..b911879 100644 (file)
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -3214,17 +3214,24 @@ fold_rtx (rtx x, rtx insn)
       if (const_arg0 == 0 || const_arg1 == 0)
        {
          struct table_elt *p0, *p1;
-         rtx true_rtx = const_true_rtx, false_rtx = const0_rtx;
+         rtx true_rtx, false_rtx;
          enum machine_mode mode_arg1;
 
-#ifdef FLOAT_STORE_FLAG_VALUE
          if (SCALAR_FLOAT_MODE_P (mode))
            {
+#ifdef FLOAT_STORE_FLAG_VALUE
              true_rtx = (CONST_DOUBLE_FROM_REAL_VALUE
                          (FLOAT_STORE_FLAG_VALUE (mode), mode));
+#else
+             true_rtx = NULL_RTX;
+#endif
              false_rtx = CONST0_RTX (mode);
            }
-#endif
+         else
+           {
+             true_rtx = const_true_rtx;
+             false_rtx = const0_rtx;
+           }
 
          code = find_comparison_args (code, &folded_arg0, &folded_arg1,
                                       &mode_arg0, &mode_arg1);
@@ -3332,8 +3339,17 @@ fold_rtx (rtx x, rtx insn)
                                                  const_arg1))
                              || (REG_P (folded_arg1)
                                  && (REG_QTY (REGNO (folded_arg1)) == ent->comparison_qty))))
-                       return (comparison_dominates_p (ent->comparison_code, code)
-                               ? true_rtx : false_rtx);
+                       {
+                         if (comparison_dominates_p (ent->comparison_code, code))
+                           {
+                             if (true_rtx)
+                               return true_rtx;
+                             else
+                               break;
+                           }
+                         else
+                           return false_rtx;
+                       }
                    }
                }
            }
index 5d65d97..09b1972 100644 (file)
@@ -1,3 +1,8 @@
+2008-09-13  Raksit Ashok <raksit@google.com>
+
+       PR rtl-optimization/37489
+       * g++.dg/opt/cse3.C: New.
+
 2008-09-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR testsuite/37495
diff --git a/gcc/testsuite/g++.dg/opt/cse3.C b/gcc/testsuite/g++.dg/opt/cse3.C
new file mode 100644 (file)
index 0000000..a632807
--- /dev/null
@@ -0,0 +1,48 @@
+// This testcase resulted in invalid code generation on x86_64 targets
+// due to a bug in fold_rtx. For a "true" value, fold_rtx represented it
+// as const_true_rtx in floating-point mode, if the FLOAT_STORE_FLAG_VALUE
+// macro is not defined.
+
+// { dg-do run }
+// { dg-options "-O1 -fno-guess-branch-probability -fcse-follow-jumps -fgcse -frerun-cse-after-loop" }
+
+class StatVal {
+
+ public:
+
+  StatVal(double ev, double va)
+    : m(ev),
+      v(va) {}
+
+  StatVal(const StatVal& other)
+    : m(other.m),
+      v(other.v) {}
+
+  StatVal& operator*=(const StatVal& other) {
+    double A = m == 0 ? 1.0 : v / (m * m);
+    double B = other.m == 0 ? 1.0 : other.v / (other.m * other.m);
+    m = m * other.m;
+    v = m * m * (A + B);
+    return *this;
+  }
+
+  double m;
+  double v;
+};
+
+extern "C" void abort (void);
+
+const StatVal two_dot_three(2, 0.3);
+
+int main(int argc, char **argv) {
+
+  StatVal product3(two_dot_three);
+
+  product3 *= two_dot_three;
+
+  if (product3.v > 2.5)
+  {
+    abort();
+  }
+  return 0;
+}