-O2 bug on PII

Marc Espie espie@bonnie.liafa.jussieu.fr
Fri Jul 3 15:55:00 GMT 1998


I'm not too familiar with the architecture, so I can't comment
with what's going on.

Anyway, start with a run-of-the-mill redhat-5.0, import
cvs egcs (gcc/ChangeLog ends with 
Wed Jul 1 21:27:13 1998  J"orn Rennecke), build with
CFLAGS=-O2 configure --enable-haifa --enable-shared,
then compile the following:
//-----------------------------------------

extern "C" int printf  (const char* format, ...);

struct redraw_info
	{
	double cs1, sn1, cs2, sn2, cs3, sn3, cs4, sn4, cs5, sn5, cs6, sn6;
	double scale, p1, p2;
	};

static inline void rotate(double &xr, double &yr, double x, double y, 
	double cs, double sn)
	{
	double r = x * cs + y * sn;
	yr =  y * cs - x * sn;
	xr = r;
	}

int main()
{
int dimension = 4;
		double a[4];
		struct redraw_info inf;
		struct redraw_info *info = &inf;
	info->p1 = 1;
	info->p2 = 1;
	info->scale = 1;
	info->cs1 = 1;
	info->cs2 = 1;
	info->cs3 = 1;
	info->cs4 = 1;
	info->cs5 = 1;
	info->cs6 = 1;
	info->sn1 = 0;
	info->sn2 = 0;
	info->sn3 = 0;
	info->sn4 = 0;
	info->sn5 = 0;
	info->sn6 = 0;
		a[0] = -620;
		a[1] = 68;
		a[2] = -684;
		a[3] = 112;
		for (unsigned i = 0; i < 3; i++)
			{
			double ap0, ap1, ap2, ap3;
			if (dimension >= 4)
				{
				rotate(ap0, ap3, a[0], a[3], info->cs4, info->sn4);
				rotate(ap1, ap3, a[1], ap3, info->cs5, info->sn5);
				rotate(ap2, ap3, a[2], ap3, info->cs6, info->sn6);
				double zp = (ap3+info->p1);
				ap0 /= zp;
				ap1 /= zp;
				ap2 /= zp;
				rotate(ap0, ap2, ap0, ap2, info->cs1, info->sn1);
				rotate(ap1, ap2, ap1, ap2, info->cs2, info->sn2);
				}
			rotate(ap0, ap1, ap0, ap1, info->cs3, info->sn3);
			printf("%lf\n", ap1);
			}
		}

//----------------------------------------------
g++ -O2 outputs:
0.026009
0.000230
0.000002

whereas it should output 3 times the same number:
0.60177
which is what it does with -O.

Assembly output available on request, or as
ftp://bonnie.liafa.jussieu.fr/pub/espie/bug.tgz

--
	Marc Espie (Marc.Espie@liafa.jussieu.fr)



More information about the Gcc-bugs mailing list