2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / opt / cse3.C
bloba63280716807ab7dc2c9a56793b875d732117990
1 // This testcase resulted in invalid code generation on x86_64 targets
2 // due to a bug in fold_rtx. For a "true" value, fold_rtx represented it
3 // as const_true_rtx in floating-point mode, if the FLOAT_STORE_FLAG_VALUE
4 // macro is not defined.
6 // { dg-do run }
7 // { dg-options "-O1 -fno-guess-branch-probability -fcse-follow-jumps -fgcse -frerun-cse-after-loop" }
9 class StatVal {
11  public:
13   StatVal(double ev, double va)
14     : m(ev),
15       v(va) {}
17   StatVal(const StatVal& other)
18     : m(other.m),
19       v(other.v) {}
21   StatVal& operator*=(const StatVal& other) {
22     double A = m == 0 ? 1.0 : v / (m * m);
23     double B = other.m == 0 ? 1.0 : other.v / (other.m * other.m);
24     m = m * other.m;
25     v = m * m * (A + B);
26     return *this;
27   }
29   double m;
30   double v;
33 extern "C" void abort (void);
35 const StatVal two_dot_three(2, 0.3);
37 int main(int argc, char **argv) {
39   StatVal product3(two_dot_three);
41   product3 *= two_dot_three;
43   if (product3.v > 2.5)
44   {
45     abort();
46   }
47   return 0;