home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!convex!news.utdallas.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!quorum.COM!brown
- From: brown@quorum.COM (Robert E. Brown)
- Subject: missing optimization: remainder & register variable
- Message-ID: <9211130110.AA11595@_grettir.quorum.com_>
- Sender: gnulists@ai.mit.edu
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Thu, 12 Nov 1992 15:10:32 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 97
-
- I am running GCC 2.3.1 on a Sun Sparcstation. GCC was compiled with
- "configure sun4".
-
- When NEEDLESS_REMAINDER is not defined in the following function, GCC
- optimizes away the computation of (temp % 33), but with NEEDLESS_REMAINDER
- defined, the optimization doesn't happen. Remainder is implemented in a
- subroutine on my machine, so it's expensive.
-
- If the xxx variable is assigned to a different register, the optimized
- assembly code is always produced -- NEEDLESS_REMAINDER doesn't make a
- difference.
-
-
- % cat wow5.c
- ============
-
-
- #ifdef NEEDLESS_REMAINDER
- register long xxx asm ("%o0");
- #endif
-
-
- void *
- foobar()
- {
- long temp;
-
- temp = 1;
- temp = temp % 33;
-
- if (temp == 0)
- short_computation();
- else if (temp == 1)
- long_computation();
- }
-
-
-
- % gcc-2.3.1 -O -S wow5.c -v
- ===========================
-
- Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.1/specs
- gcc version 2.3.1
- /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
- GNU CPP version 2.3.1 (sparc)
- /usr/local/lib/gcc-lib/sun4/2.3.1/cc1 /usr/tmp/cca04461.i -quiet -dumpbase wow5.c -O -version -o wow5.s
- GNU C version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
-
-
- % cat wow5.s
- ============
-
- gcc2_compiled.:
- .text
- .align 4
- .global _foobar
- .proc 0120
- _foobar:
- !#PROLOGUE# 0
- save %sp,-136,%sp
- !#PROLOGUE# 1
- call _long_computation,0
- nop
- ret
- restore
-
-
- % gcc-2.3.1 -O -S wow5.c -v -DNEEDLESS_REMAINDER
- ================================================
-
- Reading specs from /usr/local/lib/gcc-lib/sun4/2.3.1/specs
- gcc version 2.3.1
- /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
- GNU CPP version 2.3.1 (sparc)
- /usr/local/lib/gcc-lib/sun4/2.3.1/cc1 /usr/tmp/cca04465.i -quiet -dumpbase wow5.c -O -version -o wow5.s
- GNU C version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
- wow5.c:3: warning: call-clobbered register used for global register variable
-
- thor [299] cat wow5.x s
- gcc2_compiled.:
- .text
- .align 4
- .global _foobar
- .proc 0120
- _foobar:
- !#PROLOGUE# 0
- save %sp,-136,%sp
- !#PROLOGUE# 1
- mov 1,%o1
- mov %o1,%o0
- call .rem,0
- mov 33,%o1
- call _long_computation,0
- nop
- ret
- restore
-
-