[Bug c++/49338] wrong code with -O2 and -O3

hsmeier at arcor dot de gcc-bugzilla@gcc.gnu.org
Thu Jun 9 09:44:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49338

--- Comment #8 from Hans Meier <hsmeier at arcor dot de> 2011-06-09 09:44:28 UTC ---
(In reply to comment #7)
> It isn't hard to rewrite it using an union:

a similar solution with a union was one of my earlier attempts to
performance-optimize our code. unfortunately this lead to a horrible
performance
degrade - the critical realtime thread of our application was 60% slower then.
analysis showed that things were not kept in registers but instead we had a fp
push and pop in the assembly (with 4.5.1). the code looked like this:

union{double d;U8 uc[8];} rv;
rv.d=m_Value.Value;
rv.uc[0]=rv.uc[0] & ~((U8)1);
return rv.d;

maybe your version with U64 instead of double at the input to the union doesn't
suffer this performance penalty, so i will try it and if it performs good i
certainly will switch to this solution.

otherwise yes, -Wstrict-aliasing=1 and -Wstrict-aliasing=2 both warn, I just
thought -Wstrict-aliasing which in fact is described as being equivalent to
-Wstrict-aliasing=3 and thus included in -Wall would detect more than =1 or =2

so far and most important, thanks a lot for the immediate help!



More information about the Gcc-bugs mailing list