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

Matti Niemenmaa matti.niemenmaa+news at iki.fi
Mon Jul 15 00:26:24 PDT 2013


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.




More information about the llvm-commits mailing list