[PATCH] Use PMINU/PMAXU for UGE/ULE vector comparison on X86

Juergen Ributzka juergen at apple.com
Mon Jul 15 14:23:51 PDT 2013


On Jul 15, 2013, at 10:52 AM, Juergen Ributzka <juergen at apple.com> wrote:

> 
> On Jul 15, 2013, at 12:26 AM, Matti Niemenmaa <matti.niemenmaa+news at iki.fi> wrote:
> 
>> 
>> 
>> 
>> On 2013-07-12 03:04, Juergen Ributzka wrote:
>>> there are no unsigned integer vector comparisons on x86. Therefore they are converted to signed comparisons that require flipping of the sign bits and sometimes negation of the result. There are two special cases that can be expressed with min/max instead and reduce the overall required instructions.
>>> 
>>> a <= b —> a == min(a,b)
>>> a >= b —> a == max(a,b)
>>> 
>>> Depending on if SSE2 or SSE41 is available this can be applied to only i8 or i8/i16/i32 based vectors.
>>> 
>>> This patch is based on the idea from Ian Ollmann who originally suggested this improvement.
>>> 
>>> Please see the attached diff file for the patch to LowerVSETCC and a small test case.
>> 
>> It seems to me that the following two, which avoid flipping the sign
>> bits although they do need negation, are also possible:
>> 
>> a > b --> a != min(a,b)
>> a < b --> a != max(a,b)
>> 
>> They may not be improvements, though: with <16 x i8>, "a > b" consists
>> of loading a constant, two xors, and a compare, whereas "a != min(a,b)"
>> results in a min, two compares, and a xor. While avoiding the load is
>> nice, I suspect that the original version performs better.
> 
> Good question! Let me check it with a micro benchmark if there is any measurable difference. Even if there is no improvement I would still go for the conversion just to save a few extra instructions and to get rid of the load.

Hi Matti,

I tested it and unfortunately the min/max conversion leads to slower code for ULT and UGT. The ULE and UGE cases are approximately 50% faster with the conversion.

-Juergen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130715/c1bf9b9e/attachment.html>


More information about the llvm-commits mailing list