Intrinsics are marked as inline now. However gcc knows what they do, and is able to optimize out some code code which uses them - e.g. in example below both count1a() and count2a() are optimized to "mov eax, 5; ret". Because of this intrinsics could be marked as constexpr. This would allow gcc to better optimize code. It also would allow to perform quick code validation in tools like Compiler Explorer, by using code like below. #include "immintrin.h" constexpr int data[8] = {0, 1, 0, 2, 0, 3}; constexpr int count1(const int* d) { int cnt = 0; for (int n = 0; n < 8; ++n) if (0 == d[n]) ++cnt; return cnt; } int count1a() { return count1(data); } inline int count2(const int* d) { __m256i v = _mm256_loadu_si256((const __m256i*)d); v = _mm256_cmpeq_epi32(v, _mm256_setzero_si256()); return _mm256_movemask_epi8(v) >> 2; } int count2a() { return count1(data); }
Confirmed. Note this trivially applies to all open-coded intrinsics not using __builtin_ia32_* calls, marking those constexpr would require significant work (work that might be useful anyways for optimization, of course).
SIMD ISAa for other CPU types (e.g. ARM/AARCH64 NEON) also can benefit from this.
Is this request to make just x86_64 intrinsics constexpr or all of them? (IMO, all intrinsics that could be should be made constexpr -- see bug 70816 for a target-independent example; some others may have already been made to work to help libstdc++).
For tracking purposes it probably would be better to have separate issues for every CPU type which could benefit this. So this one could be for x86, and you could open other requests for other CPUs which supports SIMD instructions.