From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27825 invoked by alias); 23 Sep 2011 15:53:38 -0000 Received: (qmail 27796 invoked by uid 22791); 23 Sep 2011 15:53:37 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from usmamail.tilera.com (HELO USMAMAIL.TILERA.COM) (206.83.70.75) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 23 Sep 2011 15:53:23 +0000 Received: from [10.7.0.51] (10.9.0.23) by USMAExch2.tad.internal.tilera.com (10.3.0.33) with Microsoft SMTP Server id 14.0.694.0; Fri, 23 Sep 2011 11:53:22 -0400 Message-ID: <4E7CAB71.10901@tilera.com> Date: Fri, 23 Sep 2011 16:05:00 -0000 From: Jeff Kenton User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: Ian Lance Taylor CC: David Brown , Georg-Johann Lay , , Subject: Re: Tr : [redundency elimination, code motion, commun expression elimination] GCC optimizations References: <1316712613.83211.YahooMailNeo@web28503.mail.ukl.yahoo.com> <1316721552.42227.YahooMailNeo@web28508.mail.ukl.yahoo.com> <4E7C4771.40803@gjlay.de> <4E7C4CCA.2010001@westcontrol.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg00193.txt.bz2 On 09/23/2011 11:16 AM, Ian Lance Taylor wrote: > David Brown writes: > >>> It's the same for >>> >>> if (x == 1) { a=b; c=d; e=f; foo(); } >>> else if (x == 2) { a=b; c=d; e=f; foo(); } >>> >>> GCC don't factor out the common part >>> >> You are right - which is odd, since there is no reason why it could >> not (unlike the original case where there is no "else"). Surely this >> would count as a significant missed optimisation, especially for big >> switch() code. > I don't think it is a significant missed optimization, as people rarely > write code like that. They normally write > > if (x == 1 || x == 2) { a=b; c=d; e=f; foo(); } > > The proposed optimization only applies when somebody has laboriously > written out the exact same sequence of code twice. > > I'm not opposed to such an optimization if it works reliably and is not > too expensive. I just don't think it will make much difference on > ordinary code. > > Ian People don't write that kind of code (we hope), but machine generated code can have all kinds of weirdness. Still not a big deal, but it might be more common than you think. --jeff