Vc icon indicating copy to clipboard operation
Vc copied to clipboard

clang++ 7 miscompiles AVX, AVX2 with 1.3 branch

Open kfjahnke opened this issue 5 years ago • 1 comments

Ubuntu 19.04 just came out, so I gave it a spin. It contains the vc-dev package in version 1.3.4 and clang++ is now version 7 by default. These two don't seem to go together well when compiling with -mavx or -mavx2. I get this error:

In file included from /usr/local/include/Vc/scalar/../common/../avx/../sse/casts.h:31:
/usr/local/include/Vc/scalar/../common/../sse/intrinsics.h:617:13: error: argument to ```
'__builtin_ia32_vec_ext_v4sf' must be a constant integer
            _MM_EXTRACT_FLOAT(f, v, i);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/clang/7.0.0/include/smmintrin.h:890:11: note: expanded from macro '_MM_EXTRACT_FLOAT'
  { (D) = __builtin_ia32_vec_ext_v4sf((__v4sf)(__m128)(X), (int)(N)); }
`

I found a quick fix, but it may be too quick a shot. The 'i' which is fed to the macro is the default of a switch statement. I assume that instead of using 'i' one might just write plain literal '4', because this is the only thing which seems to make sense there, and it is in fact an immediate and compiles fine. What do you say? The modified code would simply be (intrinsics.h, 608ff):

`        case 0:
            f = _mm_cvtss_f32(v);
            break;
#if defined Vc_IMPL_SSE4_1 && !defined Vc_MSVC
        default:
#ifdef Vc_GCC
            f = __builtin_ia32_vec_ext_v4sf(static_cast<__v4sf>(v), 4);
#else
            // MSVC fails to compile this because it can't optimize i to an immediate
            _MM_EXTRACT_FLOAT(f, v, 4);
#endif
            break;
#else
        case 1:
`

With the 1.4 the problem is gone, but this may take several releases to trickle down, and maybe debian/ubuntu could fix this as a bug fix. If the '4' solution is okay, it could be proposed to them.

kfjahnke avatar Apr 22 '19 08:04 kfjahnke

I want to report that on macOS clang 10.0.1 (shipped with Xcode 10.2, in macOS 10.14 Mojave) has the same problem.

aledegano avatar May 21 '19 07:05 aledegano