Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Robert E. Brown
Thu, 12 Nov 1992 15:10
missing optimization: remainder & register variable
Author: Robert E. Brown
Date: Thu, 12 Nov 1992 15:10
Date: Thu, 12 Nov 1992 15:10
96 lines
2951 bytes
2951 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads