Path: utzoo!telly!ddsw1!lll-winken!killer!texbell!bigtex!milano!cs.utexas.edu!tut.cis.ohio-state.edu!WJH12.HARVARD.EDU!textware!brent From: textware!brent@WJH12.HARVARD.EDU (Brent Byer) Newsgroups: gnu.gcc.bug Subject: GCC-1.32 optimizer error Message-ID: <8901221807.AA09380@textware.uucp> Date: 22 Jan 89 18:07:59 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 89 Produced on Sun3 (w/OS3.x), GCC-1.32 (host=Sun3os3 target=Sun3os3) [ Looks like few people use reg/shorts, huh? ] It is a win in the scene I have. ------------------- foo.c ------------------- foo(ai) int ai; { extern short gfoo[]; register short i, pp; if((i = ai) == 0) return(-1); pp = gfoo[i]; return(pp); } ----------------------- foo.s No Optimization ( gcc -traditional -S -c foo.c ) ----------------------- #NO_APP gcc_compiled.: .text .even .globl _foo _foo: link a6,#0 movel d2,sp@- movew a6@(10),d1 tstw d1 jne L2 moveq #-1,d0 jra L1 L2: movew d1,d0 extl d0 asll #1,d0 lea _gfoo,a0 movew a0@(d0:l),d2 movew d2,d0 extl d0 jra L1 L1: movel a6@(-4),d2 unlk a6 rts ------------------------- foo.s With Optimization ( gcc -O -traditional -S -c foo.c ) ------------------------- #NO_APP gcc_compiled.: .text .even .globl _foo _foo: link a6,#0 movew a6@(8),d0 jne L2 moveq #-1,d0 jra L1 L2: lea _gfoo,a0 movew a0@(d0:w:2),d0 extl d0 L1: unlk a6 rts --------------------------- Note that the optimizer has used the wrong half of the parameter. a6@(8) vs. a6@(10) Congratulations to rms et al @FSF. The GCC compiler does an excellent job. Truly embarrasses those laid-back lazy other ones. I especially liked how it remembered that it had the possibly useful side-effect of getting the remainder via a division, and then seeing an attempt to produce that same remainder, it just snags it with a simple reach into a side-pocket. Nice one. (That x/y ... x%y ... is a *not* infrequent combination). regards, brent byer