<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Recognise unsigned comparisons with signed comparison instructions"
href="https://bugs.llvm.org/show_bug.cgi?id=33138">33138</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Recognise unsigned comparisons with signed comparison instructions
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>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
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>