[Bug middle-end/88487] union prevents autovectorization
bugzilla@poradnik-webmastera.com
gcc-bugzilla@gcc.gnu.org
Thu Dec 20 21:17:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88487
--- Comment #6 from Daniel Fruzynski <bugzilla@poradnik-webmastera.com> ---
Not good. Fortunately I found workaround. This is probably the best what one
can get:
[code]
#include <stddef.h>
#include <stdint.h>
template<typename Type>
struct TypeHelper
{
constexpr unsigned offset();
operator Type&()
{
uint8_t*__restrict p = (uint8_t*__restrict)this - offset();
Type*__restrict pt = (Type*__restrict)p;
return *pt;
}
};
struct S
{
struct Union
{
void*__restrict*__restrict ptr;
TypeHelper<double*__restrict*__restrict> d;
} u;
};
template<>
constexpr unsigned TypeHelper<double*__restrict*__restrict>::offset()
{
return offsetof(S::Union, d) - offsetof(S::Union, ptr);
}
void test(S* __restrict s1, S* __restrict s2)
{
for (int n = 0; n < 2; ++n)
{
s1->u.d[n][0] = s2->u.d[n][0];
s1->u.d[n][1] = s2->u.d[n][1];
}
}
[/code]
More information about the Gcc-bugs
mailing list