This is an archive of the discontinued LLVM Phabricator instance.

Fix the SSE4 byte sign extension in a cleaner way, and more thoroughly test that our intrinsics behave the same under -fsigned-char and -funsigned-char.
ClosedPublic

Authored by chandlerc on Sep 30 2015, 8:24 PM.

Details

Summary

This further testing uncovered that AVX-2 has a broken cmpgt for 8-bit
elements, and has for a long time. This is fixed in the same way as
SSE4 handles the case.

The other ISA extensions currently work correctly because they use
specific instruction intrinsics. As soon as they are rewritten in terms
of generic IR, they will need to add these special casts. I've added the
necessary testing to catch this however, so we shouldn't have to chase
it down again.

I considered changing the core typedef to be signed, but that seems like
a bad idea. Notably, it would be an ABI break if anyone is reaching into
the innards of the intrinsic headers and passing __v16qi on an API
boundary. I can't be completely confident that this wouldn't happen due
to a macro expanding in a lambda, etc., so it seems much better to leave
it alone. It also matches GCC's behavior exactly.

A fun side note is that for both GCC and Clang, -funsigned-char really
does change the semantics of __v16qi. To observe this, consider:

% cat x.cc
#include <smmintrin.h>
#include <iostream>

int main() {
  __v16qi a = { 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  __v16qi b = _mm_set1_epi8(-1);
  std::cout << (int)(a / b)[0] << ", " << (int)(a / b)[1] << '\n';
}
% clang++ -o x x.cc && ./x
-1, 1
% clang++ -funsigned-char -o x x.cc && ./x
0, 1

However, while this may be surprising, both Clang and GCC agree.

Diff Detail

Repository
rL LLVM

Event Timeline

chandlerc updated this revision to Diff 36178.Sep 30 2015, 8:24 PM
chandlerc retitled this revision from to Fix the SSE4 byte sign extension in a cleaner way, and more thoroughly test that our intrinsics behave the same under -fsigned-char and -funsigned-char..
chandlerc updated this object.
chandlerc added a reviewer: rsmith.
chandlerc added a subscriber: cfe-commits.
rsmith accepted this revision.Sep 30 2015, 8:29 PM
rsmith edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 30 2015, 8:29 PM
This revision was automatically updated to reflect the committed changes.