This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

possible loop optimization error (czrrent snapshot)


The testcase below outputs 0 instead of 1, when compiled with

-O1 -fstrength-reduce -frerun-loop-opt -ffast-math

with the current and some older pgcc, and the current egcs (taken
from cvs yesterday), on i686-pc-linux-gnu.

(the program output is self-explaining)

The bug seems to be triggered by -ffast-math, which enables some
fp-comparison reversals during jump optimization, causing the second strength
reduce pass to fail (seems!). It seems, while xsum is calculcated correctly,
the comparison of xsum < 1e-6 fails.

Sorry that I couldn't provide more info. The testcase was sent to me by
Krysztof Strasburger.


#include<stdio.h>
#include<math.h>
struct {
    double c[9];
    int nat;
} coord;
int fmbug()
{
    int kpix, kpiy, kpiz;
    double xsum, ysum, zsum;
    int i, kpi;

    xsum = 0.;
    ysum = 0.;
    zsum = 0.;
    for (i = 1; i <= coord.nat; ++i) {
	xsum += fabs(coord.c[i * 3 - 3]);
	ysum += fabs(coord.c[i * 3 - 2]);
	zsum += fabs(coord.c[i * 3 - 1]);
    }
    kpix = 0;
    kpiy = 0;
    kpiz = 0;
    if (xsum < 1e-6) {
	kpix = 1;
    }
    if (ysum < 1e-6) {
	kpiy = 1;
    }
    if (zsum < 1e-6) {
	kpiz = 1;
    }
    kpi = kpix + kpiy + kpiz;
    printf ("%d %d %d\n",kpix,kpiy,kpiz);
 /*  Next instruction removes the error. */
 /*  printf ("%f %f %f\n",xsum,ysum,zsum); */
    return kpi;
}

main()
{
    int i;
    for (i = 1; i <= 3; ++i) {
	coord.c[i * 3 - 3] = 0.;
	coord.c[i - 1] = 0.;
    }
    coord.c[4] = -1.5662804877;
    coord.c[7] = 1.5662804877;
    coord.c[5] = 1.3377370267;
    coord.c[8] = 1.3377370267;
    coord.nat = 3;
    printf("result (should be 1) = %d\n",fmbug());
}

                                                          |


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]