This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Seeing Source-level Optimisations
- From: Andrew Talbot <Andrew dot Talbot at talbotville dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 15 Apr 2006 16:29:02 +0100
- Subject: 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.