🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #298

optimization missed

#298
From: Dirk Grunwald
Date: Wed, 26 Jul 1989 15:35
67 lines
2176 bytes
g++-1.35.1+, sun3/os4, -m68881

G++ doesn't notice that the variable `stride' is an induction variable
in the following code; stride is a private member variable. It is not
modified anywhere but at the beginning of the loop.  It should qualify
as an induction variable, but I don't think it's being considered for
this.

//--------------- C++ header to handle arrays like fortran.
class Matrix {				// by dave nichols
private:
    int *index;
    double *data;
    int stride;
public:
    Matrix( int n1, int n2, int *indx, double *dat);
    double& operator()( int i, int j );
};

static inline double&
Matrix::operator()( int i, int j ) {
    return ( data[i + j * stride ] );
}

static inline
Matrix::Matrix( int n1, int n2, int *indx, double *dat) {
    index = indx;
    data = dat;
//    for( int i =0; i<n2; i++ ) {
//	index[i] = i*n1;
//    }
    stride = n1;
}

#include <stdio.h>
#include <math.h>
#include <generic.h>

#define MATRIX(name,n1,n2)\
    int name2(name,index)[n1];\
	double name2(name,data)[n1*n2]; \
	    Matrix name(n1, n2, name2(name,index), name2(name,data));

main () {
    int	i, j, k;

    static const int n=200;
    MATRIX(x,n,n);

    double	total=0.;

    for( i=0; i<n; i++ )
	for( j=0; j<n; j++ )
	    x(i,j) = sqrt(1.+(i+1)+(j+1));
    for( i=0; i<n; i++ )
	for( j=0; j<n; j++ )
	    for( k=0; k<n; k++ )
		total = total + x(i,k) * x(k,j);
    printf("total=%f\n    1576677724. if double precision\n",
	   (double) total );
}
//   7.0sec	1575556480. 	DEC 3100  (f77 -O3)
//  13.1sec	1575559552	DEC 3100  (C++ -O2)
//
--
Dirk Grunwald -- Univ. of Illinois 		  (grunwald@flute.cs.uiuc.edu)
Technical Details
Message-ID: <GRUNWALD.89Jul26103300@flute.cs.uiuc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!cica!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!flute.cs.uiuc.edu!grunwald

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!cica!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!flute.cs.uiuc.edu!grunwald
From: grunwald@flute.cs.uiuc.edu (Dirk Grunwald)
Newsgroups: gnu.g++.bug
Subject: optimization missed
Message-ID: <GRUNWALD.89Jul26103300@flute.cs.uiuc.edu>
Date: 26 Jul 89 15:35:09 GMT
Sender: news@brutus.cs.uiuc.edu
Reply-To: grunwald@flute.cs.uiuc.edu
Distribution: gnu
Organization: University of Illinois, Urbana-Champaign
Lines: 67