Using -O2 or -O1, a case is exhibited where an update to a global register variable disappears from the assembly output. Release: 3.2 (also seen with 3.0) Environment: Linux sql-server 2.4.19-4GB #1 Fri Sep 13 13:14:56 UTC 2002 i686 unknown Suse-Linux 8.1, using binary distribution of gcc from CD-ROM. $ gcc -v Reading specs from /usr/lib/gcc-lib/i486-suse-linux/3.2/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i486-suse-linux Thread model: posix gcc version 3.2 [Bug was also seen for 3.0] How-To-Repeat: In the attached program the function convert_from_foreign_array_fill() is miscompiled. $ gcc -O0 bugO.c; a.out ; echo $? 0 $ gcc -O2 bugO.c; a.out ; echo $? 1 Please look at the code generated by gcc -O2 -S bugO.c for convert_from_foreign_array_fill() and search for lines matching ebx. You'll find three of them, but 4 in the -O0 case. The addl $4, %ebx disappeared. That was the update part of pushSTACK(). Please add this sample program to your testsuite.
From: Jim Wilson <wilson@tuliptree.org> To: gcc-gnats@gcc.gnu.org Cc: Joerg-Cyril.Hoehle@T-Systems.com, gcc-bugs@gcc.gnu.org, bruno@clisp.org, sds@gnu.org Subject: Re: optimization/10684: register variable update disappears when using -O Date: Thu, 08 May 2003 16:39:10 -0400 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10684 This is related to PR c/7871 which I have already done a lot of analysis work on. There appear to be multiple bugs in the handling of global register variables, and they have been there since the gcc-3.0 release. Jim
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed, still present in 3.4-cvs. This is a reduced testcase: register int STACK __asm__("%ebx"); static void (*p) (); void f () { STACK += 1; p (); STACK -= 1; } Looking at the assembly shows that STACK += 1 ist lost if compiled with -O. The problem seems to be that life analysis adds a REG_DEAD note to the call to (*p) which makes STACK += 1 a dead store. regards Christian
It still happens on the mainline (20030607): It happens between *.20.life and *.21.combine.
Subject: Re: register variable update disappears when using -O On Sat, 2003-06-07 at 12:22, pinskia@physics.uc.edu wrote: > It still happens on the mainline (20030607): I haven't checked in any patches for this problem yet. Everything I have tried so far has broken something else. This is turning out to be a rather involved problem. I haven't worked on this in a month, I am hoping that I will have time to work on it again before the end of June. Jim
I think this is related to bug 11413 and bug 7871.
This has incorrectly not been marked as a regression, see http://gcc.gnu.org/ml/gcc/2003-08/msg01744.html Done hereby. W.
*** Bug 13414 has been marked as a duplicate of this bug. ***
global registers are evil.
this is also a regression from 3.0.4.
Okay, I found out when it started to happen: between 3.2 20020601 and 3.2 20020713 (sorry I cannot reduce the time frame now but it would be easy using the regressions scripts in contrib).
Related to bug 7871 (they really might be both caused by the same patch).
*** This bug has been marked as a duplicate of 7871 ***