home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sgi / 12855 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.9 KB  |  60 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!odin!bananapc.csd.sgi.com!ciemo
  3. From: ciemo@bananapc.csd.sgi.com (Dave Ciemiewicz)
  4. Subject: Re: Optimization problem with 3.1 compilers
  5. Message-ID: <1992Aug25.183256.3342@odin.corp.sgi.com>
  6. Sender: news@odin.corp.sgi.com (Net News)
  7. Nntp-Posting-Host: bananapc.csd.sgi.com
  8. Organization: Silicon Graphics, Customer Support Division
  9. References:  <1992Aug19.000616.8590@leland.Stanford.EDU>
  10. Date: Tue, 25 Aug 1992 18:32:56 GMT
  11. Lines: 47
  12.  
  13. In article <1992Aug19.000616.8590@leland.Stanford.EDU>, dhinds@leland.Stanford.EDU (David Hinds) writes:
  14. |> I have a program that compiles and executes reliably with the MIPS 2.1
  15. |> compilers under Irix 4.0.1, but core dumps with a segmentation violation
  16. |> when a particular function is compiled at -O2 or above with the 3.1
  17. |> compilers and Irix 4.0.5A.   Here is a short example with the problem:
  18. |> 
  19. |> > #include <stdio.h>
  20. |> > #define MAXP 12
  21. |> > 
  22. |> > void main(void)
  23. |> >   {
  24. |> >   int *i, *j, step[MAXP+1], k;
  25. |> >   double sum;
  26. |> >   float all2[MAXP+1];
  27. |> >
  28. |> >   for (k = 0; k < MAXP+1; k++) {
  29. |> >     step[k] = k; all2[k] = 2.0;
  30. |> >     }
  31. |> >
  32. |> >   sum = 0.0; k = 2;
  33. |> >   for (i = &step[2]; i <= &step[MAXP]; i++, k++) {
  34. |> >     printf("k = %d\n", k);
  35. |> >     for (j = &step[1]; j != i; j++)
  36. |> >       sum += all2[*j] - 1;
  37. |> >     }
  38. |> >   printf("Sum = %f\n", sum);
  39. |> >   }
  40. |> 
  41. |> When I compile this with 'cc -O2 bug.c' and run a.out, I get:
  42. |> 
  43. |> > k = 2
  44. |> > k = 3
  45. |> > k = 4
  46. |> > k = 5
  47. |> > k = 6
  48. |> > Segmentation fault (core dumped)
  49. |> 
  50.  
  51. I don't know if you got a response on this or not.  The problem is a bug
  52. in the 3.10 version of /usr/lib/uopt which incorrectly unrolls the inner
  53. loop "for (j = ...".  There is a bug submitted on this problem.
  54.  
  55. To work around this problem, turn off loop unrolling in uopt (see uopt(1)
  56. man page):
  57.  
  58.         cc -O2 -Wo,-loopunroll,0 bug.c -o bug.c
  59.  
  60.