https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85077
Bug ID: 85077 Summary: V[248][SD]F abs not optimized to Product: gcc Version: 8.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: kretz at kde dot org Target Milestone: --- The following test case (also at https://godbolt.org/g/XEPk7M) shows that `x < 0 ? -x : x` is not optimized to an efficient abs implementation. This is not only the case for SSE, but also for AVX and AVX512 vectors. The my_abs functions show what I'd expect the result to be. #include <x86intrin.h> template <class T, int N> using V [[gnu::vector_size(N)]] = T; auto abs(V<float, 16> x) { return x < 0 ? -x : x; } auto my_abs(V<float, 16> x) { return _mm_and_ps((__m128)(~V<unsigned, 16>() >> 1), x); } auto abs(V<double, 16> x) { return x < 0 ? -x : x; } auto my_abs(V<double, 16> x) { return _mm_and_pd((__m128d)(~V<unsigned long long, 16>() >> 1), x); }