public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13260] New: Incorrect optimisation of loop termination condition
@ 2003-12-01 15:48 stuart dot menefy at st dot com
  2003-12-01 15:51 ` [Bug c/13260] " paolo at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: stuart dot menefy at st dot com @ 2003-12-01 15:48 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-02-09 16:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
2003-12-01 15:51 ` [Bug c/13260] " paolo at gcc dot gnu dot org
2003-12-01 15:59 ` [Bug optimization/13260] [3.4 Regression] " pinskia at gcc dot gnu dot org
2003-12-01 16:04 ` pinskia at gcc dot gnu dot org
2003-12-01 16:04 ` pinskia at gcc dot gnu dot org
2003-12-04 20:10 ` cvs-commit at gcc dot gnu dot org
2003-12-04 20:35 ` amylaar at gcc dot gnu dot org
2003-12-04 21:02 ` cvs-commit at gcc dot gnu dot org
2003-12-04 21:07 ` amylaar at gcc dot gnu dot org
2004-02-09 16:03 ` dank at kegel dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).