[PATCH] D25987: [X86] New pattern to generate PSUBUS from SELECT

Yulia Koval via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 28 06:45:47 PDT 2017


yulia_koval updated this revision to Diff 97087.
yulia_koval added a comment.

In https://reviews.llvm.org/D25987#673846, @spatel wrote:

> It's difficult for me to see what's going on in these tests because there are a bunch of irrelevant load/store/gep/bitcast instructions. Can you remove those?
>
> If you do that, the root of the problem is very similar to:
>  https://reviews.llvm.org/rL286776
>
> Ie, if we recognized the umin/umax patterns in IR as ISD::UMIN/ISD::UMAX when we created the DAG, the subsequent matching to the x86-specific PSUBUS might already happen with the existing lowering?


I fixed tests(https://reviews.llvm.org/D32643). New revision is based on this updated tests revision.

We have (i16) (a>=b ? a - b : 0), where both a and b are 32 bit. We can't apply max here, because unsigned max between something and zero doesn't make sense. And we can't use signed max, because we can't fit 32bit unsigned values in it.

On the other hand, the result we select is 16bit PSUBUS, which only exists for 16bit and 8bit vector elements, not for 32bit. This optimization truncates vectors to 16bit, using the information, that it was zero extended and this vector is on the left side of the cmp. We use that information to substitute b with min(b, max_16bit_type). and then we can truncate a(it can be truncated, because it is zero extended value) and b(because we truncated it properly with our min). In this case the result of the sub will be valid when a >=b and not significant if not(the actual result is zero). This pattern can be then recognized as PSUBUS instruction.

This transformation is profitable only if PSUBUS exists. And this function is the place. where PSUBUS is selected and we can be 100% sure, that it will be profitable. This transformation is not profitable in general.

So in pseudo code it will be:
a >= b ? a - b : 0
transformed to:
trunc(a) >= min(b, 0xFFFF) ? trunc(a) - min(b, 0xFFFF) : 0 ->the result of the patch
This result is then transformed to PSUBUS by existing code.


https://reviews.llvm.org/D25987

Files:
  lib/Target/X86/X86ISelLowering.cpp
  test/CodeGen/X86/psubus.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25987.97087.patch
Type: text/x-patch
Size: 15468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170428/dd82068f/attachment-0001.bin>


More information about the llvm-commits mailing list