[llvm-bugs] [Bug 33138] New: Recognise unsigned comparisons with signed comparison instructions
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue May 23 04:27:56 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=33138
Bug ID: 33138
Summary: Recognise unsigned comparisons with signed comparison
instructions
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: llvm-bugs at lists.llvm.org, spatel+llvm at rotateright.com
SSE (without XOP) doesn't support unsigned integer comparison so the sign has
to be bit twiddled beforehand to use the signed integer comparison intrinsics:
__m128i _mm_cmpgt_epu64(__m128i a, __m128i b)
{
__m128i sign =
_mm_setr_epi32(0x00000000u,0x80000000u,0x00000000u,0x80000000u);
__m128i flipA = _mm_xor_si128( a, sign );
__m128i flipB = _mm_xor_si128( b, sign );
return _mm_cmpgt_epi64( flipA, flipB );
}
define <2 x i64> @_mm_cmpgt_epu64(<2 x i64>, <2 x i64>) {
%3 = xor <2 x i64> %0, <i64 -9223372036854775808, i64 -9223372036854775808>
%4 = xor <2 x i64> %1, <i64 -9223372036854775808, i64 -9223372036854775808>
%5 = icmp sgt <2 x i64> %3, %4
%6 = sext <2 x i1> %5 to <2 x i64>
ret <2 x i64> %6
}
We should be able to canonicalize this to icmp ugt to simplify the code for
analysis, hopefully in InstCombine but maybe DAGCombine if bitcasts prove a
problem. The other SSE comparisons are tricky as often there is a lot of
bitcasting:
__m128i _mm_cmpgt_epu8(__m128i a, __m128i b)
{
__m128i sign = _mm_set1_epi32( 0x80808080u );
__m128i flipA = _mm_xor_si128( a, sign );
__m128i flipB = _mm_xor_si128( b, sign );
return _mm_cmpgt_epi8( flipA, flipB );
}
define <2 x i64> @_mm_cmpgt_epu8(<2 x i64>, <2 x i64>) {
%3 = xor <2 x i64> %0, <i64 -9187201950435737472, i64 -9187201950435737472>
%4 = xor <2 x i64> %1, <i64 -9187201950435737472, i64 -9187201950435737472>
%5 = bitcast <2 x i64> %3 to <16 x i8>
%6 = bitcast <2 x i64> %4 to <16 x i8>
%7 = icmp sgt <16 x i8> %5, %6
%8 = sext <16 x i1> %7 to <16 x i8>
%9 = bitcast <16 x i8> %8 to <2 x i64>
ret <2 x i64> %9
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170523/2ffe5a99/attachment.html>
More information about the llvm-bugs
mailing list