[PATCH] D42935: [X86] Use min/max for vector ult/ugt compares if avoids a sign flip.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 16:13:37 PST 2018


craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon.

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.

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.


https://reviews.llvm.org/D42935

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42935.132903.patch
Type: text/x-patch
Size: 93552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180206/e8ebfd4c/attachment.bin>


More information about the llvm-commits mailing list