This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/13260] New: Incorrect optimisation of loop termination condition
- From: "stuart dot menefy at st dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 1 Dec 2003 15:48:52 -0000
- Subject: [Bug c/13260] New: Incorrect optimisation of loop termination condition
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This problem was first seen when building the Linux kernel, in the function
root_nfs_parse_addr(). I've extracted this into a small stand alone
program which demonstrates the problem.
When built with an older gcc the results are as expected, however this fails
on more recent versions of gcc. Turning the optimisation down to -O1 also
allows the program to work correctly. Also uncommenting the printf in the
middle of the code makes it work correctly.
Of the gcc versions I've tried, versions 3.0.3 and the 3.2.1
(prerelease) which SuperH ship work OK. However version 3.3.1, 3.3.2
and the latest 3.4 snapshot (20031126) all generate incorrect code.
The problem centers around a new optimisation which gcc has spotted, but
doesn't appear to get quite right.
In gcc 3.2.1 the code generated looks like:
cmp/gt r3,r7
movt r2
tst r2,r2
movt r1
cmp/pl r2
add r1,r8
bf/s .L16
mov r8,r3
In 3.3.2 it has spotted that after the 'tst' the T flag already
indicates whether to take the branch or not, and so the extra register
and comparison are redundant. However, to do this the branch has to be
reversed into a bt/s, and this is not being done:
cmp/gt r3,r7
movt r1
tst r1,r1
movt r1
add r1,r8
bf/s .L16
mov r8,r3
The code generated by 3.4 (20031126) is identical.
--------------
Compilation diagnostics:
% /var/tmp/gcc-3.4-20031126/objdir/gcc/xgcc
-B/var/tmp/gcc-3.4-20031126/objdir/gcc/ -O2 -S ipconfig.c -nostdinc -I
/opt/STM/ST40R2.1.3/sh-superh-elf/include/ -v -save-temps
Reading specs from /var/tmp/gcc-3.4-20031126/objdir/gcc/specs
Configured with: ../configure --host=i686-pc-linux-gnu --target=sh4-linux --pref
ix=/opt/STM/ST40Linux-1.0/devkit/sh4 --exec-prefix=/opt/STM/ST40Linux-1.0/devkit
/sh4 --bindir=/opt/STM/ST40Linux-1.0/devkit/sh4/bin --sbindir=/opt/STM/ST40Linux
-1.0/devkit/sh4/sbin --sysconfdir=/opt/STM/ST40Linux-1.0/devkit/sh4/etc --datadi
r=/opt/STM/ST40Linux-1.0/devkit/sh4/share --includedir=/opt/STM/ST40Linux-1.0/de
vkit/sh4/include --libdir=/opt/STM/ST40Linux-1.0/devkit/sh4/lib --libexecdir=/op
t/STM/ST40Linux-1.0/devkit/sh4/libexec --localstatedir=/opt/STM/ST40Linux-1.0/de
vkit/sh4/var --sharedstatedir=/opt/STM/ST40Linux-1.0/devkit/sh4/share --mandir=/
opt/STM/ST40Linux-1.0/devkit/sh4/man --infodir=/opt/STM/ST40Linux-1.0/devkit/sh4
/info --program-transform-name=s,^,sh4-linux-, --enable-shared --enable-language
s=c,c++ --enable-threads=posix --enable-c99 --enable-long-long --with-system-zli
b --disable-multilib --enable-symvers=gnu --enable-__cxa_atexit --with-gxx-inclu
de-dir=${prefix}/target//usr/include/g++-
Thread model: posix
gcc version 3.4 20031126 (experimental)
/var/tmp/gcc-3.4-20031126/objdir/gcc/cc1 -E -quiet -nostdinc -v -I /opt/STM/ST4
0R2.1.3/sh-superh-elf/include/ -iprefix /var/tmp/gcc-3.4-20031126/objdir/gcc/../
lib/gcc/sh4-linux/3.4/ -isystem /var/tmp/gcc-3.4-20031126/objdir/gcc/include ipc
onfig.c -O2 -o ipconfig.i
#include "..." search starts here:
#include <...> search starts here:
/opt/STM/ST40R2.1.3/sh-superh-elf/include/
/var/tmp/gcc-3.4-20031126/objdir/gcc/include
End of search list.
/var/tmp/gcc-3.4-20031126/objdir/gcc/cc1 -fpreprocessed ipconfig.i -quiet -dump
base ipconfig.c -auxbase ipconfig -O2 -version -o ipconfig.s
GNU C version 3.4 20031126 (experimental) (sh4-linux)
compiled by GNU C version 3.2.2 20030222 (Red Hat Linux 3.2.2-5).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
--
Summary: Incorrect optimisation of loop termination condition
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: stuart dot menefy at st dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: sh4-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260