home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / gcc / bug / 3258 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.4 KB  |  121 lines

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!brendan
  2. From: brendan@cygnus.com (Brendan Kehoe)
  3. Newsgroups: gnu.gcc.bug
  4. Subject: [kevinc@kpc.com: gcc v2.3.3 bug]
  5. Date: 26 Jan 1993 22:24:11 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 107
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-gcc@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301262146.AA25151@cygnus.com>
  12. Reply-To: brendan@cygnus.com (Brendan Kehoe)
  13.  
  14. ------- Start of forwarded message -------
  15. From: kevinc@kpc.com
  16. Subject: gcc v2.3.3 bug
  17. To: bug-g++@prep.ai.mit.edu
  18. Cc: kevinc@solman.kpc.com
  19. Date: Tue, 19 Jan 93 17:17:52 -0800
  20.  
  21.    I have found what I consider to be a bug in the optimizer for gcc.  I
  22. realize that the issue of whether something is a bug is not always clear
  23. when talking about a compiler's optimization.  One can always argue about
  24. how far the optimizer should go.  I am calling this a bug since code is
  25. generated which does absolutely nothing and it seems that the compiler
  26. has ample information to avoid the behavior.
  27.  
  28.    What I found is a case where the optimizer does a very good job of
  29. unrolling a loop to the point where it knows the result. It then iterates
  30. the loop anyway.
  31.  
  32.    By the way, I am not just trying to cause trouble.  I have found a true
  33. bug which causes the compiler to crash with the message "Internal compiler
  34. error" when the -funroll-loops flag is set.  I am trying to reduce the
  35. program to the smallest case which reproduces the bug.  In so doing I found
  36. the bug that I am reporting now.
  37.  
  38. Machine: Sun Sparcstation 2
  39. OS:      SunOS 4.1.3
  40. GCC:     2.3.3
  41.  
  42. C++ source code (test.cc)
  43. - ------------------------
  44. #include <stdio.h>
  45.  
  46. main () {
  47.    int i = 0 ;
  48.    for (int j = 0; j < 500000; j++) {
  49.       i += 1 ;
  50.       }
  51.    printf ("sums = %d\n", i) ;
  52.    }
  53. - ------------------------
  54.  
  55. I compile the above program with the command:
  56.  
  57. g++ -S -O2 -funroll-loops test.c
  58.  
  59. Assembler output (test.s)
  60. - ------------------------
  61. gcc2_compiled.:
  62. .text
  63.    .align 8
  64. LC0:
  65.    .ascii "sums = %d\12\0"
  66.    .align 4
  67.    .global _main
  68.    .proc 04
  69. _main:
  70.    !#PROLOGUE# 0
  71.    save %sp,-136,%sp
  72.    !#PROLOGUE# 1
  73.    call ___main,0
  74.    nop
  75.    mov 0,%o1
  76.    sethi %hi(499999),%o0
  77.    or %o0,%lo(499999),%o0
  78.    add %o1,10,%o1
  79. L26:
  80.    cmp %o1,%o0
  81.    ble,a L26
  82.    add %o1,10,%o1
  83.    sethi %hi(LC0),%o0
  84.    or %o0,%lo(LC0),%o0
  85.    sethi %hi(500000),%o1
  86.    call _printf,0
  87.    or %o1,%lo(500000),%o1
  88.    ret
  89.    restore %g0,0,%o0
  90. - -----------------
  91.  
  92. The following section from above seems to be totally unneeded.:
  93.    mov 0,%o1
  94.    sethi %hi(499999),%o0
  95.    or %o0,%lo(499999),%o0
  96.    add %o1,10,%o1
  97. L26:
  98.    cmp %o1,%o0
  99.    ble,a L26
  100.    add %o1,10,%o1
  101.  
  102. Note that the compiler has already determined the result of the loop
  103. (500000) and is using it as a constant parameter to printf.  Surely
  104. it has enough information to avoid the loop altogether.
  105.  
  106. Please acknowledge receipt of this message.  Also I would like to
  107. remain informed of the status of this bug as it passes through your
  108. system if that is possible.
  109.  
  110. Kevin Cameron
  111. kevinc@kpc.com
  112.  
  113. ------- End of forwarded message -------
  114.  
  115. --
  116. Brendan Kehoe                                               brendan@cygnus.com
  117. Cygnus Support, Mountain View, CA                              +1 415 903 1400
  118.                      ``In a cruel and imperfect world,'' says critic Rex Reed,
  119.  ``[Audrey Hepburn] was living proof that God could still create perfection.''
  120.  
  121.