public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david@westcontrol.com>
To: gcc-help@gcc.gnu.org
Cc: Georg-Johann Lay <avr@gjlay.de>,
	gcc-help@gcc.gnu.org,  charfiasma@yahoo.fr
Subject: Re: Tr : [redundency elimination, code motion, commun  expression elimination] GCC optimizations
Date: Sun, 25 Sep 2011 13:50:00 -0000	[thread overview]
Message-ID: <4E7DF22E.2010307@westcontrol.com> (raw)
Message-ID: <20110925135000.F-J0TPxQ_B3jpCYUd6biu0WSVdRMniK58YEaV-8ikdw@z> (raw)
In-Reply-To: <mcr4o03wapm.fsf@coign.corp.google.com>

On 23/09/2011 17:16, Ian Lance Taylor wrote:
> David Brown<david@westcontrol.com>  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
>

When you are talking about a simple case like this, then I agree.  The 
situation where I would expect to see it more is in switch statements 
where for various reasons you might have the same code for different 
cases, but have them separated for some reason.  Even more common is the 
situation when you have some commonality between the branches, but not 
completely identical cases.  The "tail merging" and "block merging" 
mentioned by Jeff Law sounds like optimisations to suit such cases.

It is always possible that these optimisations /are/ triggered by such 
code for current and development versions of gcc - the compiler I tested 
with was gcc 4.5.1 (since that's the version I have conveniently 
available at the moment).

David


  parent reply	other threads:[~2011-09-24 15:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1316712613.83211.YahooMailNeo@web28503.mail.ukl.yahoo.com>
2011-09-22 19:59 ` charfi asma
2011-09-22 20:51   ` Ian Lance Taylor
2011-09-23  7:04   ` David Brown
2011-09-23  8:47     ` Georg-Johann Lay
2011-09-23  9:13       ` David Brown
2011-09-23 15:16         ` David Brown
2011-09-23 15:53         ` Ian Lance Taylor
2011-09-23 16:05           ` Jeff Kenton
2011-09-23 19:03             ` Jeff Law
2011-09-27  7:18               ` Miles Bader
2011-09-27  9:35                 ` Miles Bader
2011-09-27 11:29                   ` Miles Bader
2011-09-27 16:47                     ` Amker.Cheng
2011-09-27 23:42                       ` Jeff Law
2011-09-28  0:03                     ` Re : " charfi asma
2011-09-28  8:59                       ` Miles Bader
2011-09-25 13:31           ` David Brown [this message]
2011-09-25 13:50             ` David Brown
2011-09-26 10:57             ` Re : " charfi asma
2011-09-26 15:35               ` Miles Bader
2011-09-26 22:47               ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E7DF22E.2010307@westcontrol.com \
    --to=david@westcontrol.com \
    --cc=avr@gjlay.de \
    --cc=charfiasma@yahoo.fr \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).