OSDN Git Service

[X86] Use min/max for vector ult/ugt compares if avoids a sign flip.
authorCraig Topper <craig.topper@intel.com>
Sun, 11 Feb 2018 17:11:40 +0000 (17:11 +0000)
committerCraig Topper <craig.topper@intel.com>
Sun, 11 Feb 2018 17:11:40 +0000 (17:11 +0000)
commitff687abc6ec7ce5a32e3871afbae315ab9319fe5
tree51395faed95ae989b97aaf76673bb955d0366efb
parentbafade2e5b99b4460d4eda4e30d45a7bb6ae439b
[X86] Use min/max for vector ult/ugt compares if avoids a sign flip.

Summary:
Currently we only use min/max to help with ule/uge compares because it removes an invert of the result that would otherwise be needed. But we can also use it for ult/ugt compares if it will prevent the need for a sign bit flip needed to use pcmpgt at the cost of requiring an invert after the compare.

I also refactored the code so that the max/min code is self contained and does its own return instead of setting up a flag to manipulate the rest of the function's behavior.

Most of the test cases look ok with this. I did notice that we added instructions when one of the operands being sign flipped is a constant vector that we were able to constant fold the flip into.

I also noticed that sometimes the SSE min/max clobbers a register that is needed after the compare. This resulted in an extra move being inserted before the min/max to preserve the register. We could try to detect this and switch from min to max and change the compare operands to use the operand that gets reused in the compare.

Reviewers: spatel, RKSimon

Reviewed By: RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D42935

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324842 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/avx512-insert-extract.ll
test/CodeGen/X86/avx512vl-vec-masked-cmp.ll
test/CodeGen/X86/psubus.ll
test/CodeGen/X86/vec_cmp_uint-128.ll
test/CodeGen/X86/vec_minmax_match.ll
test/CodeGen/X86/vec_setcc-2.ll