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

* [Bug c/13260] Incorrect optimisation of loop termination condition
  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 ` 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
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo at gcc dot gnu dot org @ 2003-12-01 15:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From paolo at gcc dot gnu dot org  2003-12-01 15:51 -------
Hi.Thanks for your report, but eventually you forgot to attach the snippet!

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  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 ` pinskia at gcc dot gnu dot org
  2003-12-01 16:04 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-01 15:59 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
          Component|c                           |optimization
           Keywords|                            |wrong-code
            Summary|Incorrect optimisation of   |[3.4 Regression] Incorrect
                   |loop termination condition  |optimisation of loop
                   |                            |termination condition
   Target Milestone|---                         |3.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-01 16:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-01 16:04 -------
Marking as invalid to mark it as ...

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (2 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-01 16:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-12-01 16:04 -------
unconfirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-12-04 20:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-12-04 20:10 -------
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



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: amylaar at gcc dot gnu dot org @ 2003-12-04 20:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From amylaar at gcc dot gnu dot org  2003-12-04 20:35 -------
Created an attachment (id=5275)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5275&action=view)
patch which has been applied to mainline (3.4 experimental)


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |amylaar at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-12-04 21:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-12-04 21:02 -------
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



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: amylaar at gcc dot gnu dot org @ 2003-12-04 21:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From amylaar at gcc dot gnu dot org  2003-12-04 21:07 -------
Fixed with patch

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13260


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

* [Bug optimization/13260] [3.4 Regression] Incorrect optimisation of loop termination condition
  2003-12-01 15:48 [Bug c/13260] New: Incorrect optimisation of loop termination condition stuart dot menefy at st dot com
                   ` (7 preceding siblings ...)
  2003-12-04 21:07 ` amylaar at gcc dot gnu dot org
@ 2004-02-09 16:03 ` dank at kegel dot com
  8 siblings, 0 replies; 10+ messages in thread
From: dank at kegel dot com @ 2004-02-09 16:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dank at kegel dot com  2004-02-09 16:03 -------
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!


-- 


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).