List of optimizations enabled by -O1 seems incorrect
Nikos Chantziaras
realnc@arcor.de
Thu Aug 13 20:15:00 GMT 2009
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.
More information about the Gcc-help
mailing list