This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Seeing Source-level Optimisations


Dear gcc-help,

A newbie question: does gcc have a facility to emit its source-level optimised 
source code? The reason I ask is that although it is nice to have things like 
PDCE taken care of quietly, it would be instructive to the coder to see where 
a line of code could be moved to save a duplication, for example.

I guess some source-level optimisations will add to or maintain human clarity, 
while others will be more efficient to the machine but might obfuscate the 
purpose of the code. Some optimisations are Always Right; some are 
circumstantial.

Taking the example in the "changes" for version 4.1:

    int foo (int *, int *);
    int
    bar (int d)
    {
      int a, b, c;
      b = d + 1;
      c = d + 2;
      a = b + c;
      if (d)
        {
          foo (&b, &c);
          a = b + c;
        }
      printf ("%d\n", a);
    }

"The a = b + c can be sunk to right before the printf."

If I were notified of that duplication, I would be inclined to alter the 
source code, even though the compiler would optimise the duplication out for 
me if I left it alone. One reason is that its pleasing to remove the 
superfluity, another is that if it turned out that the expression should be
a = b + 2 * c, I might alter one instance of it but miss the other.

Thanks and regards,

-- Andy Talbot.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]