https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71695
Bug ID: 71695
Summary: m68k: long long multiplication broken
Product: gcc
Version: 5.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: martin at netbsd dot org
Target Milestone: ---
Created attachment 38787
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38787&action=edit
source code demonstrating the bug
Calculating the nth power of ten in below simple program fails for all input
values != 0; i.e.:
[/tmp] martin@mac-beth > ./a.out 0
10
[/tmp] martin@mac-beth > ./a.out 1
0
[/tmp] martin@mac-beth > ./a.out 2
0
[/tmp] martin@mac-beth > ./a.out 3
0
This is due to muls.l zeroing both registers at .L3 here:
clr.l %d2
moveq #10,%d1
.L3:
muls.l %d2,%d1
move.l %d1,%d3
add.l %d3,%d3
mulu.l %d1,%d2:%d1
add.l %d3,%d2
addq.l #1,%a0
cmp.l %d0,%a0
jne .L3
This is with the gcc 5.4 version in the NetBSD source tree, identifying as:
Using built-in specs.
COLLECT_GCC=/usr/tools/bin/m68k--netbsdelf-gcc
COLLECT_LTO_WRAPPER=/usr/tools/libexec/gcc/m68k--netbsdelf/5.4.0/lto-wrapper
Target: m68k--netbsdelf
Configured with: /usr/src/tools/gcc/../../external/gpl3/gcc/dist/configure
--target=m68k--netbsdelf --enable-long-long --enable-threads
--with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD
nb1 20160606' --with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-time=rt --enable-libstdcxx-threads
--with-diagnostics-color=auto-if-env --with-sysroot=/hosts/mac68k
--with-mpc=/usr/tools --with-mpfr=/usr/tools --with-gmp=/usr/tools
--disable-nls --disable-multilib --program-transform-name=s,^,m68k--netbsdelf-,
--enable-languages='c c++ objc' --prefix=/usr/tools
Thread model: posix
gcc version 5.4.0 (NetBSD nb1 20160606)
Compiler invocation:
m68k--netbsdelf-gcc -S -Wall -O2 bug-m68k.c
Any value of -O will cause the bad code.