optimization/10623: Incorrect generation of IA-32 SSE movups via __builtin_ia32_loadups
yourst@yourst.com
yourst@yourst.com
Sun May 4 18:14:00 GMT 2003
>Number: 10623
>Category: optimization
>Synopsis: Incorrect generation of IA-32 SSE movups via __builtin_ia32_loadups
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sun May 04 17:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Matt Yourst
>Release: gcc 3.2.2
>Organization:
>Environment:
gcc from Mandrake Linux (release gcc-3.2.2-3mdk)
>Description:
When using the __builtin_ia32_loadups function, gcc generates incorrect code at all optimization levels including -O1. In some circumstances, gcc generates a "movaps" load instruction instead of the specified "movups"; the code will cause an unaligned SSE load exception when run.
Furthermore, if the (incorrectly) loaded vector is subsequently stored to another correctly aligned address, gcc places the "movups" there in place of the correct instruction, "movaps".
See below for code and commented disassembly.
>How-To-Repeat:
// Compile with gcc -O2 -msse -fomit-frame-pointer:
typedef float vec4f_t __attribute__ ((mode(V4SF)));
void test(vec4f_t* dest, float* src, int count) {
for (int i = 0; i < count; i++) {
vec4f_t v = __builtin_ia32_loadups(src + i);
dest[i] = v;
}
}
int main() {
vec4f_t dest[64];
float src[64];
test(dest, src, 64-4);
}
/*
Dump of assembler code for function _Z4testPU8__vectorfPfi:
mov 0xc(%esp,1),%eax
test %eax,%eax
jle 0x80483ef <_Z4testPU8__vectorfPfi+31>
mov 0x4(%esp,1),%ecx
mov 0x8(%esp,1),%edx
movaps (%edx),%xmm0 << INCORRECT: this should be movups (%edx),%xmm0
movups %xmm0,(%ecx) << INCORRECT: this should be movaps %xmm0,(%ecx)
add $0x4,%edx
add $0x10,%ecx
dec %eax
jne 0x80483e0 <_Z4testPU8__vectorfPfi+16>
ret
*/
>Fix:
Unknown; only workaround is to compile at -O0 or use inline assembly instead of __builtin_ia32_loadups intrinsic.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list