From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23376 invoked by alias); 14 Jan 2003 20:59:41 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 23361 invoked from network); 14 Jan 2003 20:59:37 -0000 Received: from unknown (HELO mail-out2.apple.com) (17.254.0.51) by 209.249.29.67 with SMTP; 14 Jan 2003 20:59:37 -0000 Received: from mailgate1.apple.com (A17-128-100-225.apple.com [17.128.100.225]) by mail-out2.apple.com (8.11.3/8.11.3) with ESMTP id h0EKxPI07766; Tue, 14 Jan 2003 12:59:25 -0800 (PST) Received: from scv1.apple.com (scv1.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.2.5) with ESMTP id ; Tue, 14 Jan 2003 12:58:55 -0800 Received: from physics.uc.edu (il0503d-dhcp84.apple.com [17.205.38.84]) by scv1.apple.com (8.11.3/8.11.3) with ESMTP id h0EKxMs03598; Tue, 14 Jan 2003 12:59:22 -0800 (PST) Date: Wed, 15 Jan 2003 00:15:00 -0000 Subject: Re: optimizations Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v551) Cc: gcc-help , "gcc@gcc.gnu.org" To: Reza Roboubi From: Andrew Pinski In-Reply-To: <3E24749A.46E2CC1B@linisoft.com> Message-Id: <0E499A65-2803-11D7-9221-00039372607E@physics.uc.edu> Content-Transfer-Encoding: 7bit X-SW-Source: 2003-01/txt/msg00701.txt.bz2 What version of gcc? This seems like it was fixed at one point doing the 3.x series because it does not happen with 3.3 (prerelease) or 3.4 (experimental). Thanks, Andrew Pinski On Tuesday, Jan 14, 2003, at 12:35 US/Pacific, Reza Roboubi wrote: > In the following code, it is clear that the return value of mm() can be > eliminated. In fact, many optimizations are possible here. Yet gcc > seems not > to be able to do these optimizations. Below, I posted the assembly > code that > gcc generated (for the while() loop). > > I compiled this code with gcc -O2 -Wall. > > I was wondering if I am doing something wrong. If not, then please > comment on > current gcc developments in this regard, and what it takes to add some > of these > features. > > Please also comment on how other compilers would compare with gcc in > this case. > > Are there any non-obvious remedies you have for this case? > > PS: Please tell me if I must report this as a gcc bug. > > Thanks in advance for any help you provide. > > > inline int mm(int *i) > { > if((*i)==0x10){return 0;} > (*i)++;return 1; > } > > int > main(){ > > int k=0; > while (mm(&k)){} > write(1,&k,1); > > return 0; > } > > > Associated assembly code for the while() loop: > > 0x80483b0 : mov 0xfffffffc(%ebp),%eax > 0x80483b3 : xor %edx,%edx > 0x80483b5 : cmp $0x10,%eax > 0x80483b8 : je 0x80483c3 > 0x80483ba : inc %eax > 0x80483bb : mov $0x1,%edx > 0x80483c0 : mov %eax,0xfffffffc(%ebp) > 0x80483c3 : test %edx,%edx > 0x80483c5 : jne 0x80483b0 >