From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17046 invoked by alias); 19 Jul 2005 04:00:59 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 17006 invoked by uid 22791); 19 Jul 2005 04:00:54 -0000 Received: from yosemite.airs.com (HELO yosemite.airs.com) (205.217.158.180) by sourceware.org (qpsmtpd/0.30-dev) with SMTP; Tue, 19 Jul 2005 04:00:54 +0000 Received: (qmail 1374 invoked by uid 10); 19 Jul 2005 04:00:52 -0000 Received: (qmail 17082 invoked by uid 500); 19 Jul 2005 04:00:45 -0000 Mail-Followup-To: gcc-help@gcc.gnu.org, ming.lei@oracle.com To: Lei Ming Cc: gcc-help@gcc.gnu.org Subject: Re: GCC Unrolling Simple Loop Generates Rubbish Code? References: <200507191049.49412.ming.lei@oracle.com> From: Ian Lance Taylor Date: Tue, 19 Jul 2005 04:00:00 -0000 In-Reply-To: <200507191049.49412.ming.lei@oracle.com> Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2005-07/txt/msg00171.txt.bz2 Lei Ming writes: > This simple code: > > int > main (void) > { > int s = 0; > int i; > for (i = 0; i < 100; i++) > s += i; > return 0; > } > > After compiled with "-O3 -funroll-all-loops", will generate this piece of > assembly code for the loop: > > movl $99, %eax > .L6: > subl $25, %eax <== > jns .L6 > xorl %eax, %eax > leave > ret I tried compiling with current gcc mainline with -O3 -funroll-all-loops. I got this: 0: 55 push %ebp 1: 31 c0 xor %eax,%eax 3: 89 e5 mov %esp,%ebp 5: 83 ec 08 sub $0x8,%esp 8: 83 e4 f0 and $0xfffffff0,%esp b: 83 ec 10 sub $0x10,%esp e: c9 leave f: c3 ret So I think things are better now. I also see the behaviour you report with gcc 3.2.3. It does seem pretty incomprehensible. Since it seems to be fixed, I haven't bothered to figure out why it used to behave like that. Ian