Article View: gnu.gcc.bug
Article #205bug in gcc version 1.40 for mc68k
From: 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).
Technical Details
Message-ID:
<199207310440.AA24617@blilly.UUCP>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!broadcast.sony.COM!bin%blillyShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!broadcast.sony.COM!bin%blilly From: bin%blilly@broadcast.sony.COM (Program Administrator) Subject: bug in gcc version 1.40 for mc68k Message-ID: <199207310440.AA24617@blilly.UUCP> Sender: gnulists@ai.mit.edu Reply-To: lilb@sony.compuserve.com Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 30 Jul 1992 20:40:21 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 79