Testcase: #include <emmintrin.h> #include <stdio.h>
typedef float floatA __attribute__((__may_alias__)); int main() { __m128 x = _mm_setzero_ps(); int i; for (i = 0; i < 4; ++i) { const float xx = ((floatA*)&x)[i]; if (xx != 0.f) { printf("%d: %f\n", i, xx); return -1; } } return 0; } This fails with -O2, as well as with -O2 -fno-strict-aliasing. It works with -O1 and -O0. The generated assembly shows that the stack is created but not initialized and then read from and checked whether it's 0. If instead of const float xx = ((floatA*)&x)[i]; you write const float xx = ((floatA*)&x)[0]; (or any other constant between 0 and 3) then the testcase doesn't fail. Tested versions: 4.2.4: doesn't fail 4.3.2: fails 4.3.3: fails 4.4.0: doesn't fail -- Summary: accessing aliased __m128 miscompiles Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kretz at kde dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40141