This is an archive of the discontinued LLVM Phabricator instance.

[X86] Lower _mm[256|512]_[mask[z]]_avg_epu[8|16] intrinsics to native llvm IR
ClosedPublic

Authored by ytsafrir on Sep 7 2017, 5:02 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

ytsafrir created this revision.Sep 7 2017, 5:02 AM
craig.topper edited edge metadata.Sep 7 2017, 9:43 AM

You need to remove the bultins from include/clang/Basic/BuiltinsX86.def too.

ytsafrir updated this revision to Diff 114523.Sep 10 2017, 7:00 AM

Removed the AVG builtins from ./include/clang/Basic/BuiltinsX86.def

This revision is now accepted and ready to land.Sep 11 2017, 9:26 AM
This revision was automatically updated to reflect the committed changes.
MatzeB added a subscriber: MatzeB.Sep 20 2017, 5:36 PM

With this commit some (old) code stops to compile as it seems to remove some builtins, was that intentional?

Reproducer:

typedef long long __m128i __attribute__((__vector_size__(16)));
typedef short __v8hi __attribute__((__vector_size__(16)));
typedef char __v16qi __attribute__((__vector_size__(16)));

__m128i __attribute__((__always_inline__, __nodebug__))
_mm_avg_epu8(__m128i a, __m128i b)
{
  return (__m128i)__builtin_ia32_pavgb128((__v16qi)a, (__v16qi)b);
}

__m128i __attribute__((__always_inline__, __nodebug__))
_mm_avg_epu16(__m128i a, __m128i b)
{
  return (__m128i)__builtin_ia32_pavgw128((__v8hi)a, (__v8hi)b);
}
$ clang t.c
/Users/mbraun/t.c:8:19: error: use of unknown builtin '__builtin_ia32_pavgb128'
      [-Wimplicit-function-declaration]
  return (__m128i)__builtin_ia32_pavgb128((__v16qi)a, (__v16qi)b);
                  ^
/Users/mbraun/t.c:8:10: error: invalid conversion between vector type '__m128i'
      (vector of 2 'long long' values) and integer type 'int' of different size
  return (__m128i)__builtin_ia32_pavgb128((__v16qi)a, (__v16qi)b);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/mbraun/t.c:14:19: error: use of unknown builtin '__builtin_ia32_pavgw128'
      [-Wimplicit-function-declaration]
  return (__m128i)__builtin_ia32_pavgw128((__v8hi)a, (__v8hi)b);
                  ^
/Users/mbraun/t.c:14:10: error: invalid conversion between vector type '__m128i'
      (vector of 2 'long long' values) and integer type 'int' of different size
  return (__m128i)__builtin_ia32_pavgw128((__v8hi)a, (__v8hi)b);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.

Actually, looking at the change it seems like it is and we better try to update emmintrin.h...

Was the code not using emmintrin.h and instead copied code from it that used the builtins?

Was the code not using emmintrin.h and instead copied code from it that used the builtins?

Turned out to be code that had been preprocessed in the past. I'll unpreprocess the xmmintrin.h/emmintrin.h parts now.

Turned out to be code that had been preprocessed in the past. I'll unpreprocess the xmmintrin.h/emmintrin.h parts now.

Could you please update if this has resolved the issue?