User account creation filtered due to spam.

Bug 8599 - [3.2 regression] loop unroll bug with -march=k6-3
Summary: [3.2 regression] loop unroll bug with -march=k6-3
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: ---
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2002-11-16 01:06 UTC by 162919
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host: i386-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 162919 2002-11-16 01:06:01 UTC
[ Reported to the Debian BTS as report #162919.
  Please CC 162919@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/162919 ]

Release:
3.2.1 (Debian) (Debian unstable)

Environment:
System: Debian GNU/Linux (unstable)
Architecture: i686
[reproducible with gcc-3.2.1 20021111 and HEAD 20021103]

the following simple code produces a segfault when compiled using gcc
3.2 using the folloing command line:

gcc -march=k6-3 -O3 -ffast-math -funroll-loops -fomit-frame-pointer
-fexpensive-optimizations -fstrict-aliasing -pipe -Wall -Werror
-fno-common -o foo foo.c

---8<---

void *array[4];

int
main ()
{
	int i;

	for (i = 0; i < sizeof (array) / sizeof (array[0]); i++)
		array[i] = 0;
	return 0;
}

---8<---

The following is the resulting asm (-S instead of -o foo). Lines
begining with "*" are annotations. Non-useful lines are omitted.

	movl	$array+4, %eax
	movl	$array, %edx
	cmpl	$array+13, %eax
	movl	$array+12, %ecx
	jb	.L10
	.loc 1 9 0
	movl	$0, (%edx)
	.loc 1 8 0
	addl	$4, %edx
	cmpl	%ecx, %edx
	ja	.L9
.L10:
	subl	$array-1, %ecx
	shrl	$4, %ecx

*	            ^^^   set to 0

	.p2align 5,,7
.L28:
	.loc 1 9 0
	movl	$0, (%edx)
	movl	$0, 4(%edx)
	movl	$0, 8(%edx)
	movl	$0, 12(%edx)
	.loc 1 8 0
	addl	$16, %edx
	loop	.L28

*	^^^ %ecx is 0 for the first pass and thus this loop becomes
*	effectively infinite causing %edx to overflow the array.

.L9:
	.loc 1 10 0
	ret
[snip]
	.string "GNU C 3.2.1 20020924 (Debian prerelease)"

	
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  binutils       2.12.90.0.1-5  The GNU assembler, linker and binary utiliti
ii  libc6          2.2.5-11.2     GNU C Library: Shared libraries and Timezone
host: i386-linux
Configured with: /home/packages/gcc/3.2/gcc-3.2-3.2.1ds5/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Comment 1 Eric Botcazou 2002-11-21 06:25:04 UTC
Responsible-Changed-From-To: unassigned->ebotcazou
Responsible-Changed-Why: Already fixed on mainline. Backporting.
Comment 2 Eric Botcazou 2002-11-22 13:33:33 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed.
Comment 3 Eric Botcazou 2002-11-22 21:20:05 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/8599
Date: 22 Nov 2002 21:20:05 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	ebotcazou@gcc.gnu.org	2002-11-22 13:20:05
 
 Modified files:
 	gcc            : ChangeLog doloop.c loop.c 
 
 Log message:
 	PR optimization/8599
 	
 	Merge from mainline:
 	2002-11-04  Dale Johannesen  <dalej@apple.com>
 	
 	* doloop.c (doloop_modify_runtime):  Fix loop count computation
 	for unrolled loops.
 	* loop.c (loop_invariant_p):  Support calling from unroller.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.142&r2=1.13152.2.657.2.143
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doloop.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.16.8.2&r2=1.16.8.3
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.389.2.7.2.4&r2=1.389.2.7.2.5
 
Comment 4 Franz Sirl 2002-11-28 04:29:32 UTC
State-Changed-From-To: closed->open
State-Changed-Why: Reopen, backported fix From Dale causes a regression on powerpc-linux-gnu.
    The testcase gcc.c-torture/execute/961213-1.c now fails with -O2 -funroll-loops.
    Presumably the backported patch relies on some other changes in the mainline.
Comment 5 Eric Botcazou 2002-12-21 12:51:15 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed, hopefully correctly this time.
Comment 7 Eric Botcazou 2002-12-21 20:31:16 UTC
From: ebotcazou@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: optimization/8599
Date: 21 Dec 2002 20:31:16 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	ebotcazou@gcc.gnu.org	2002-12-21 12:31:16
 
 Modified files:
 	gcc            : ChangeLog doloop.c 
 
 Log message:
 	PR optimization/8599
 	* doloop.c (doloop_modify_runtime): Fix loop count computation
 	for preconditioned unrolled loops.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.13152.2.657.2.166&r2=1.13152.2.657.2.167
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doloop.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.16.8.4&r2=1.16.8.5