This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
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
Hi.Thanks for your report, but eventually you forgot to attach the snippet!
Created an attachment (id=5253) [edit] Test file
Created an attachment (id=5254) [edit] Pre-processed source file
Marking as invalid to mark it as ...
unconfirmed.
Subject: Bug 13260 CVSROOT: /cvs/gcc Module name: gcc Changes by: amylaar@gcc.gnu.org 2003-12-04 20:10:29 Modified files: gcc : ChangeLog gcc/config/sh : sh-protos.h sh.c sh.h sh.md Log message: PR optimization/13260 * sh-protos.h (sh_expand_t_scc): Declare. * sh.h (PREDICATE_CODES): Add cmpsi_operand. * sh.c (cmpsi_operand, sh_expand_t_scc): New functions. * sh.md (cmpsi): Use cmpsi_operand. If T_REG is compared to something that is not a CONST_INT, copy it into a pseudo register. (subc): Fix description of new T value. (slt, sgt, sge, sgtu): Don't clobber T after rtl generation is over. (sltu, sleu, sgeu): Likewise. (seq, sne): Likewise. Use sh_expand_t_scc. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1915&r2=2.1916 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh-protos.h.diff?cvsroot=gcc&r1=1.50&r2=1.51 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.c.diff?cvsroot=gcc&r1=1.239&r2=1.240 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.h.diff?cvsroot=gcc&r1=1.227&r2=1.228 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.md.diff?cvsroot=gcc&r1=1.162&r2=1.163
Created an attachment (id=5275) [edit] patch which has been applied to mainline (3.4 experimental)
Subject: Bug 13260 CVSROOT: /cvs/gcc Module name: gcc Changes by: amylaar@gcc.gnu.org 2003-12-04 21:02:34 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.c-torture/execute: 20031204-1.c Log message: 2003-12-04 Stuart Menefy <stuart.menefy@st.com> J"orn Rennecke <joern.rennecke@superh.com> PR optimization/13260 * gcc.c-torture/execute/20031204-1.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3226&r2=1.3227 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20031204-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed with patch
A backport of this patch to gcc-3.3.3 was written by SUGIOKA Toshinobu and is (mistakenly) archived as http://www.m17n.org/linux-sh/ml/linux-sh/2003-02/msg00014.html It causes no regressions on sh4 in gcc-3.3.3-20040131's C, C++, and libstdc++ testsuites, nor in the part of the glibc-2.3.2 testsuite that I usually run. I was surprised and pleased to see that it also fixed my testcase for PR11587!