home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / gcc / bug / 2739 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.8 KB  |  110 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!convex!news.utdallas.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!quorum.COM!brown
  3. From: brown@quorum.COM (Robert E. Brown)
  4. Subject: missing optimization: remainder & register variable
  5. Message-ID: <9211130110.AA11595@_grettir.quorum.com_>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 12 Nov 1992 15:10:32 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 97
  12.  
  13. I am running GCC 2.3.1 on a Sun Sparcstation.  GCC was compiled with
  14. "configure sun4".
  15.  
  16. When NEEDLESS_REMAINDER is not defined in the following function, GCC
  17. optimizes away the computation of (temp % 33), but with NEEDLESS_REMAINDER
  18. defined, the optimization doesn't happen.  Remainder is implemented in a
  19. subroutine on my machine, so it's expensive.
  20.  
  21. If the xxx variable is assigned to a different register, the optimized
  22. assembly code is always produced -- NEEDLESS_REMAINDER doesn't make a
  23. difference.
  24.  
  25.  
  26. % cat wow5.c
  27. ============
  28.  
  29.  
  30. #ifdef NEEDLESS_REMAINDER
  31. register long xxx asm ("%o0");
  32. #endif
  33.  
  34.  
  35. void *
  36. foobar()
  37. {
  38.     long temp;
  39.     
  40.     temp = 1;
  41.     temp = temp % 33;
  42.     
  43.     if (temp == 0)
  44.     short_computation();
  45.     else if (temp == 1)
  46.     long_computation();
  47. }
  48.  
  49.  
  50.  
  51. % gcc-2.3.1 -O -S wow5.c -v
  52. ===========================
  53.  
  54. Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.1/specs
  55. gcc version 2.3.1
  56.  /usr/local/lib/gcc-lib/sun4/2.3.1/cpp -lang-c -v -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ wow5.c /usr/tmp/cca04461.i
  57. GNU CPP version 2.3.1 (sparc)
  58.  /usr/local/lib/gcc-lib/sun4/2.3.1/cc1 /usr/tmp/cca04461.i -quiet -dumpbase wow5.c -O -version -o wow5.s
  59. GNU C version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
  60.  
  61.  
  62. % cat wow5.s
  63. ============
  64.  
  65. gcc2_compiled.:
  66. .text
  67.     .align 4
  68.     .global _foobar
  69.     .proc    0120
  70. _foobar:
  71.     !#PROLOGUE# 0
  72.     save %sp,-136,%sp
  73.     !#PROLOGUE# 1
  74.     call _long_computation,0
  75.     nop
  76.     ret
  77.     restore
  78.  
  79.  
  80. % gcc-2.3.1 -O -S wow5.c -v -DNEEDLESS_REMAINDER
  81. ================================================
  82.  
  83. Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.1/specs
  84. gcc version 2.3.1
  85.  /usr/local/lib/gcc-lib/sun4/2.3.1/cpp -lang-c -v -DNEEDLESS_REMAINDER -undef -D__GNUC__=2 -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ wow5.c /usr/tmp/cca04465.i
  86. GNU CPP version 2.3.1 (sparc)
  87.  /usr/local/lib/gcc-lib/sun4/2.3.1/cc1 /usr/tmp/cca04465.i -quiet -dumpbase wow5.c -O -version -o wow5.s
  88. GNU C version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
  89. wow5.c:3: warning: call-clobbered register used for global register variable
  90.  
  91. thor [299]  cat wow5.x s
  92. gcc2_compiled.:
  93. .text
  94.     .align 4
  95.     .global _foobar
  96.     .proc    0120
  97. _foobar:
  98.     !#PROLOGUE# 0
  99.     save %sp,-136,%sp
  100.     !#PROLOGUE# 1
  101.     mov 1,%o1
  102.     mov %o1,%o0
  103.     call .rem,0
  104.     mov 33,%o1
  105.     call _long_computation,0
  106.     nop
  107.     ret
  108.     restore
  109.  
  110.