Created attachment 50014 [details] nbody-update-velocity.cpp In the following sample GCC (-O3 -ffast-math) fails to vectorize operations. The results is that GCC 10.2 does 8 mulsd, while clang 11.0 does 4 mulpd. struct vec3 { double x, y, z; }; void update_velocities(vec3* __restrict velocity, double const* __restrict mass, vec3 const* __restrict dpos, double const* __restrict mag) { velocity[0] -= dpos[0] * (mass[1] * mag[0]); velocity[1] += dpos[0] * (mass[0] * mag[0]); } See an attachment for the complete sample.
It's fixed in current trunk https://godbolt.org/z/63576n
There's t.ii:21:9: note: ==> examining statement: a$x_1 = *dpos_10(D).x; t.ii:21:9: missed: BB vectorization with gaps at the end of a load is not supported t.ii:27:6: missed: not vectorized: relevant stmt not supported: a$x_1 = *dpos_10(D).x; t.ii:21:9: note: Building vector operands of 0x4047278 from scalars instead which we eventually can improve. With AVX2 we split into one AVX and one SSE part and then run into a duplicate PR where we end up with conflicting vector types for a load which we do not yet support. We then end up with only vectorizing the AVX part.
(In reply to Hongtao.liu from comment #1) > It's fixed in current trunk https://godbolt.org/z/63576n I can confirm that now GCC does use packed multiplication mulpd. Although it is used somewhat inefficiently. The original program contained 8 multiplications and clang does 4 packed multiplication. GCC trunk does 6 packed multiplications. https://godbolt.org/z/EabPxT
I retested the sample on GCC 11.2. https://godbolt.org/z/xrarP3zbY Compared to Clang 12.0.1 GCC still generates 6 more instructions in total and does 6 mulpd against Clang's 4 mulpd.
For the trunk (without -ffast-math), the perms are done too early: vect__5.32_53 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 1, 1 }>; vect__5.33_54 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 1, 0 }>; vect__5.34_55 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 0, 0 }>; _3 = *mag_9(D); _58 = {_3, _3}; vect__4.35_59 = vect__5.32_53 * _58; vect__4.35_60 = vect__5.33_54 * _58; vect__4.35_61 = vect__5.34_55 * _58; With -ffast-math: a$x_1 = *dpos_10(D).x; a$y_11 = *dpos_10(D).y; _49 = {a$x_1, a$y_11}; _35 = _49 * _58; And the PERM is done too early the same way ..