[Bug tree-optimization/37449] [4.4 Regression] calculix gets wrong answer for -O1 -ffast-math
jakub at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Wed Oct 15 09:48:00 GMT 2008
------- Comment #17 from jakub at gcc dot gnu dot org 2008-10-15 09:47 -------
Testcase where only one constant, not two alternative constants, are on the
entry of the threaded bb.
extern int printf (const char *, ...);
void
__attribute__((noinline))
test (double cn, int *neig)
{
double tt, al[3];
*neig = 3;
if (__builtin_fabs(cn) > 1.)
cn = -1.;
tt = __builtin_atan2 (__builtin_sqrt (1. - __builtin_pow (cn, 2.)), cn)
* 3.333333333333333e-1;
al[0] = __builtin_cos (tt);
al[1] = __builtin_cos (2.0943951023931944 + tt);
al[2] = __builtin_cos (4.1887902047863879 + tt);
if ((__builtin_fabs ( al[0] - al[1]) < 1.e-5)
|| (__builtin_fabs (al[0] - al[2]) < 1.e-5)
|| (__builtin_fabs (al[1] - al[2]) < 1.e-5))
*neig = 2;
}
int
main ()
{
int neig;
test (-1.0, &neig);
printf ("neig = %d\n", neig);
if (neig != 2)
__builtin_abort ();
test (1.0, &neig);
printf ("neig = %d\n", neig);
if (neig != 2)
__builtin_abort ();
test (-2.0, &neig);
printf ("neig = %d\n", neig);
if (neig != 2)
__builtin_abort ();
return 0;
}
At -O2 -funsafe-math-optimizations, before ccp3 we have:
D.1262_38 = __builtin_pow (-1.0e+0, 2.0e+0);
D.1263_40 = 1.0e+0 - D.1262_38;
D.1264_41 = __builtin_sqrt (D.1263_40);
D.1265_43 = __builtin_atan2 (D.1264_41, -1.0e+0);
tt_45 = D.1265_43 *
3.33333333333333314829616256247390992939472198486328125e-1;
D.1266_46 = __builtin_cos (tt_45);
D.1267_47 = tt_45 + 2.094395102393194374457152662216685712337493896484375e+0;
D.1268_48 = __builtin_cos (D.1267_47);
D.1269_49 = tt_45 + 4.1887902047863878607358856243081390857696533203125e+0;
D.1270_50 = __builtin_cos (D.1269_49);
and neither ccp3, nor pre is able to optimize it out, only fab optimizes the
first call (pow) and then dom2 handles the rest.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|4.5.0 |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37449
More information about the Gcc-bugs
mailing list