This is the mail archive of the 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]

hpux20 pointer optimization bug

Sorry about losing the test case insertion the first time.

The following test case is meant to reproduce in gcc a bug which occurs
more frequently with -O in g77. Run on egcs-19980517.  Same problem
occurs whether or not --with-gnu-as is chosen (although it's not
trackable without gdb).

This bug is seen in gcc only with the combination -O -funroll-loops. It
results in a SIGSEGV when run under gdb 4.17.  It goes away if any of
the following is done:

reduce level of loop nesting (apparently the pointers are trashed when
leaving the middle level loop)

use saner notation, replacing e.g. aj[i] by a[j][i].  This notation was used in
order to simulate the treatment of the corresponding Fortran code.

put offending code in main()

This code has been run on a number of compilers and architectures, and
runs incorrectly only with gnu compilers on hppa.  It's worse in
gcc-0.5.23 (not restricted to triple nested or unrolled loops).

More often than not, -O code runs faster than -O2, but I have not seen
any numerical differences in results.  There are a few cases where
-funroll-loops slows code down by more than a factor of 2.  Are these
known HAIFA effects or a problem with hppa support?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define RK8 double
#define NI 1000                 /* Number Inverts for 32mb+
                                 * systems */
 /* #define NI 200 *//* Number Inverts for < 32mb systems */

#define NN 51                   /* 51x51 matrix size */
void Gauss(RK8  a[NN][NN], RK8 b[NN][NN], int n)
    /* Invert matrix a -> b  by Gauss method */
    RK8 d, temp, c,*aj,*ak;
    int i, j, k, m, nn, *ipvt;

    nn = n;

    for (k = 0; k < nn; k++) {
        d = (ak=a[k])[k];
        for (j = 0; j < k; j++) {
            c = (aj=a[j])[k] / d;
            for (i = 0; i < nn; i++)
                aj[i] -= ak[i] * c;
            aj[k] = c;


int main()
    RK8 **pool[NI];             /* pool of matrices to
                                 * invert */
    RK8 avg_err, total_time, time1;
    int i, j, n;
    char invert_id[2][6] = {"Gauss", "Crout"};
    struct tm *ptm;
    time_t crtime;
    FILE *fp;

    RK8 a[NN][NN],ai[NN][NN];
                Gauss(a , ai, NN);

    return EXIT_SUCCESS;

           To:                                              INTERNET - IBMMAIL

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