Testcase (see also https://godbolt.org/g/H2xjNc for GCC and Clang build): ======== #include <immintrin.h> #include <stdint.h> __attribute__((target("sse4.2"))) unsigned aeshash(const uint8_t *p, size_t len, unsigned seed) { const auto l = [](unsigned data) { __m128i m = _mm_insert_epi32(_mm_setzero_si128(), data, 1); return _mm_extract_epi32(m, 1); }; return l(seed); }======== In the testcase above, if the source is compiled with base options for x86 (either 32- or 64-bit mode), GCC fails to compile with error: /usr/lib/gcc/x86_64-linux-gnu/6.3.0/include/smmintrin.h:447:1: error: inlining failed in call to always_inline 'int _mm_extract_epi32(__m128i, int)': target specific option mismatch _mm_extract_epi32 (__m128i __X, const int __N) ^~~~~~~~~~~~~~~~~ <source>:9:38: note: called from here return _mm_extract_epi32(m, 1); ^ Clang compiles the above just fine. The compilation works if I add __attribute__((target("sse4.2"))) to the lambda.
Hmm, I think it would make sense if lambdas (and nested functions) "inherit" both target and optimize attributes from their parents.
Richard, can you actually reproduce this? I can't with the released 7.1.0 (given the error message I doubt submitter was actually using a 7 pre). Neither I can reproduce it with 6.3.0, anyway. I'm passing, as requested, -m32 -msse4.1 (or -m32 -msse4.2)
Ah, ok, now I get it, the issue is that it should be accepted without, say, -m32 -msse4.1, on the command line.
Confirmed. > g++-7 t.C -S In file included from /usr/lib64/gcc/x86_64-suse-linux/7/include/immintrin.h:37:0, from t.C:1: t.C: In lambda function: t.C:9:19: error: ‘__builtin_ia32_vec_set_v4si’ needs isa option -m32 -msse4.1 __m128i m = _mm_insert_epi32(_mm_setzero_si128(), data, 1); ^ > g++-7 t.C -S -O In file included from /usr/lib64/gcc/x86_64-suse-linux/7/include/immintrin.h:37:0, from t.C:1: /usr/lib64/gcc/x86_64-suse-linux/7/include/smmintrin.h: In lambda function: /usr/lib64/gcc/x86_64-suse-linux/7/include/smmintrin.h:447:1: error: inlining failed in call to always_inline ‘int _mm_extract_epi32(__m128i, int)’: target specific option mismatch _mm_extract_epi32 (__m128i __X, const int __N) ^~~~~~~~~~~~~~~~~ t.C:10:36: note: called from here return _mm_extract_epi32(m, 1); ^ In file included from /usr/lib64/gcc/x86_64-suse-linux/7/include/immintrin.h:37:0, from t.C:1: /usr/lib64/gcc/x86_64-suse-linux/7/include/smmintrin.h:406:1: error: inlining failed in call to always_inline ‘__m128i _mm_insert_epi32(__m128i, int, int)’: target specific option mismatch ... This is with 7.2.1 (rev. 253227) but 7.1.0 and 7.2.0 are affected the same, so is 6.4.0. GCC 5 rejects the testcase on unknown C++ grounds. The key is to _not_ pass -msse4.2 -- it shouldn't be necessary given the target attribute and as the following testcase dropping the lambda shows: #include <immintrin.h> #include <stdint.h> __attribute__((target("sse4.2"))) unsigned aeshash(const uint8_t *p, size_t len, unsigned seed) { __m128i m = _mm_insert_epi32(_mm_setzero_si128(), seed, 1); return _mm_extract_epi32(m, 1); }