Re: Tr : [redundency elimination, code motion, commun expression elimination] GCC optimizations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/23/2011 11:16 AM, Ian Lance Taylor wrote:
David Brown<david@xxxxxxxxxxxxxxx>  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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux