Regarding GCC Optimization flags and a customized profiler

2012-06-19 Thread Parang Saraf
Hi,

I have developed a small profiler which uses AMD's IBS (Instruction
Based Samling) to profile a program. With the help of it, I am able to
generate quite detailed information about the program like how many
times there is a branch miss for each branch or which instructions are
causing a lot of cache misses and several other similar information.

Now, I plan to use this information to enable certain optimization
flags for GCC. Say for example, now that I know the branch probability
I can enable the branch probability optimization flag (similar to
gprof).

My Goal: is to generate meaningful information from the profiled data
for "all" the optimization flags that GCC supports. That is, based on
the data should we enable certain optimization or not.

My Problem: I am not familiar with many of the optimization flags. The
description provided in the GCC manual for each optimization flag is
not sufficient for a thorough understanding.

Expected Solution: 1. If you can point me to resources where I can
find more in-depth information about the optimization flags.
2. Or If you think, this is exciting and you would like to collaborate
with me. I am a PhD student and I am pretty good with systems. So, if
you have a decent knowledge of compilers, feel free to contact. There
are a lot many things we can develop in this area.

Regards
Parang


Weird optimization flags behavior

2012-08-05 Thread Parang Saraf
Hi,

I am facing some weird issues with the optimization flags. I tried
posting this in the gcc-help but got no response. Here is my query:

I can see the flags enabled for each optimization level using "gcc -Q
-On -help=optimizers" (flags enabled)
Also, when I compile a program for a particular optimization level, I
can see the flags used by gcc using, "gcc -Q -v -On program.c" (flags
used).
I am working with gcc 4.4.5. I found a few anomalies, which are mentioned below:

1. There are a few flags which are documented in O1 but are enabled
for O0. Example: -funit-at-a-time. This flag is both enabled and used
at O0
2. There are a few flags, which are documented in O1 and are not
enabled for O0 (which is correct), but are still used for O0. Example:
-fauto-inc-dec flag is documented in O1 and is not enabled for O0 but
is still used by O0.
3. Flags which are enabled but are not used. Example: flags -fdce and
-fdse are enabled for O0, O1 but is never used by the compiler.
4. Here is the complete list of flags distribution:
O0: documented 0; enabled 35; used 43
O1: documented 26; enabled 56; used 66
O2: documented 55; enabled 80; used 91
O3: documented 61; enabled 86; used 97

I understand that there are a few flags which are used internally by
the gcc. But my question is, if some of the flags are shown as enabled
for a particular optimization level, why are they are not used during
compilation?

Also, ideally if I am using -O0, i should not be able to add/enable
optimization flags. But when i enable some of the O1 optimization
flags at O0, I could see gcc using them. For example: "gcc -Q -v -O0
-ftree-fre program.c". Here -ftree-fre is an optimization flag from
O1, but still it gets enabled at -O0.

Most importantly: How can I make my gcc 4.5.4 adhere strictly with the
4.5.4 documentation? If I have to recompile gcc and make some changes
to the config files, then please let me know.

I will greatly appreciate your response in this regard.

Regards
Parang