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
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.2.1
: P3 normal
Target Milestone: ---
Assignee: Eric Botcazou
Keywords: wrong-code
Depends on:
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
Known to work:
Known to fail:
Last reconfirmed:


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 on replies.
  Log of report can be found at ]

3.2.1 (Debian) (Debian unstable)

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


void *array[4];

main ()
	int i;

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


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
	subl	$array-1, %ecx
	shrl	$4, %ecx

*	            ^^^   set to 0

	.p2align 5,,7
	.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.

	.loc 1 10 0
	.string "GNU C 3.2.1 20020924 (Debian prerelease)"

| 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  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
Subject: optimization/8599
Date: 22 Nov 2002 21:20:05 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	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  <>
 	* doloop.c (doloop_modify_runtime):  Fix loop count computation
 	for unrolled loops.
 	* loop.c (loop_invariant_p):  Support calling from unroller.
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
Subject: optimization/8599
Date: 21 Dec 2002 20:31:16 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	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.