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]

Re: List of optimizations enabled by -O1 seems incorrect


On 08/13/2009 09:06 PM, Andrew Haley wrote:
Nikos Chantziaras wrote:
I'm trying to discover which GCC optimization is responsive for a
runtime error reported by Valgrind:

"Conditional jump or move depends on uninitialised value(s)"

This pops up when compiling with -O1 and above.  The code in question is
C++ and is of this form:

if (!foo&& !bar)

The uninitialized variable is 'bar'.  However, it shouldn't be evaluated
at all due to short-circuit if rules.  Of course the optimizer is free
to evaluate it anyway if there are no side-effects when doing so.

So just out of interest, I'm trying to find out which optimization is
responsible for this.  I looked up the GCC info pages and I compiled
with -O1 and then disabled the optimizations enabled by -O1 one by one,
in hope to hit the one that triggers the error, until all of them were
disabled in the end:
 [...]

However, the error still appears which makes me conclude that the above
list of -O1 optimizations is not complete.  Which ones am I missing?

Not all optimizations are switchable. If you want to know the complete set of switches, compile with -fverbose-asm and look at the .s file.

Thanks for the tip. Looking at the generated assembly files, I finally solved the "mystery": GCC uses SSE/SSE2 instructions to fetch both variables in one CPU instruction. It's faster but circumvents short-circuit "if" rules and Valgrind prints an error.



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