LLVM error with SSE4.1 intrinsics and LTO

Hi all,

I posted this to llvm-dev but didn't get any response, I'm re-trying
here in case it is related to the clang driver somehow.

The following program does not link correctly when using LTO:

"clang -flto -msse4.1 test.c"

#include <smmintrin.h>

int main() {
    __m128i a = _mm_set1_epi32(2);
    __m128i b = _mm_set1_epi32(1);
    __m128i c = _mm_min_epi32(a, b); // or _mm_max_epi32
    return c[0] == 0; // just so c doesn't opt away
}

It works fine without "-flto".

I've reproduced this using 3.4.2 as well as 3.5 (from trunk) on both
Linux and OS X.

Am I missing some flags to tell the linker to enable sse4.1? Or is
there a bug here?

Any pointers are appreciated! Thank you!

-Chris

Hello,

I posted this to llvm-dev but didn't get any response, I'm re-trying
here in case it is related to the clang driver somehow.

The following program does not link correctly when using LTO:

"clang -flto -msse4.1 test.c"

#include <smmintrin.h>

int main() {
   __m128i a = _mm_set1_epi32(2);
   __m128i b = _mm_set1_epi32(1);
   __m128i c = _mm_min_epi32(a, b); // or _mm_max_epi32
   return c[0] == 0; // just so c doesn't opt away
}

It works fine without "-flto".

I've reproduced this using 3.4.2 as well as 3.5 (from trunk) on both
Linux and OS X.

Am I missing some flags to tell the linker to enable sse4.1? Or is
there a bug here?

There is: http://llvm.org/bugs/show_bug.cgi?id=15792 (includes a workaround)

Jonathan

Passing the right mcpu flag to the linker solves my problem on linux,
which is enough to get me unstuck for now.

Thanks for the pointer!