[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)
commitca5a3401718e31141458194e031d1d8d45aded91
treeb07227f9adbe623c6cf40413d283aecf24dbe952
parentc2544c572af1026cd0b5da020e9506dcdd8f206c
[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

llvm-svn: 324842
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/avx512-insert-extract.ll
llvm/test/CodeGen/X86/avx512vl-vec-masked-cmp.ll
llvm/test/CodeGen/X86/psubus.ll
llvm/test/CodeGen/X86/vec_cmp_uint-128.ll
llvm/test/CodeGen/X86/vec_minmax_match.ll
llvm/test/CodeGen/X86/vec_setcc-2.ll