Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Program Administrator
Thu, 30 Jul 1992 20:40
bug in gcc version 1.40 for mc68k
Author: Program Administrator
Date: Thu, 30 Jul 1992 20:40
Date: Thu, 30 Jul 1992 20:40
77 lines
2481 bytes
2481 bytes
Consider the following simple program which returns the position of the first '1'
bit in an integer (in this case should return 2).
int main()
{
register int x = 4;
int i;
for(i=0; i<8 && ((x&1) == 0); x >>= 1, i++)
;
return(i);
}
When compiled by "gcc -v -O -S gcctest.c", the following results:
gcc version 1.40
/usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68k -Dunix -Dunixpc -D__mc68k__ -D__unix__ -D__unixpc__ -D__OPTIMIZE__ gcctest.c /usr/tmp/cca24532.cpp
GNU CPP version 1.40
/usr/local/lib/gcc-cc1 /usr/tmp/cca24532.cpp -quiet -dumpbase gcctest.c -O -version -o gcctest.s
GNU C version 1.40 (68k, AT&T UnixPC/gas) compiled by GNU C version 1.40.
default target switches:
.file "gcctest.c"
gcc_compiled.:
.text
.even
.globl _main
_main:
link a6,#0
movel d2,sp@-
moveq #4,d1
moveq #0,d0
L5:
btst #0,d1
jne L3
asrl #1,d1
addql #1,d0
moveq #7,d2
cmpl d0,d2
jge L5
L3:
movel a6@(-4),d2
unlk a6
rts
This works as expected (return value 2). However, when the -fstrength-reduce flag is added, we get:
gcc version 1.40
/usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68k -Dunix -Dunixpc -D__mc68k__ -D__unix__ -D__unixpc__ -D__OPTIMIZE__ gcctest.c /usr/tmp/cca24537.cpp
GNU CPP version 1.40
/usr/local/lib/gcc-cc1 /usr/tmp/cca24537.cpp -quiet -dumpbase gcctest.c -fstrength-reduce -O -version -o gcctest.s
GNU C version 1.40 (68k, AT&T UnixPC/gas) compiled by GNU C version 1.40.
default target switches:
.file "gcctest.c"
gcc_compiled.:
.text
.even
.globl _main
_main:
link a6,#0
moveq #4,d1
moveq #7,d0
L5:
btst #0,d1
jne L3
asrl #1,d1
dbra d0,L5
clrw d0
subql #1,d0
jcc L5
moveq #8,d0
L3:
unlk a6
rts
This does not work properly (it returns 5, rather than 2).
Other compilation options (e.g. -fcombine-regs) do not appear to alter this behavior.
I've not had any other problems with -fstrength-reduce, but it clearly causes major
problems with the above code fragment (simplified from a real program).
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