Transform vector SET{LE/ULT/ULE} -> SETLT and SET{GE/UGT/UGE} -> SETGT if possible
authorNoah Goldstein <goldstein.w.n@gmail.com>
Tue, 14 Feb 2023 01:39:05 +0000 (19:39 -0600)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 15 Feb 2023 00:59:03 +0000 (18:59 -0600)
commitf3732c2b18df305a1927b9d4a94610421a2750e7
treeb70832e7cb749352d5ca281dc2bb7f7d785aec93
parent3e0866bf616bf7b293cec93d06d030dd11d7911f
Transform vector SET{LE/ULT/ULE} -> SETLT and SET{GE/UGT/UGE} -> SETGT if possible

SETLT and SETGT can use `{v}pcmpgt` directly whereas the other SETCC
variants require some other instructions as well. On AVX512, which has
vector comparisons for all SETCC variants, this can still be
preferable if the destination is a vector. And if the destination is a
mask, its the same performance.

The transform for unsigned SETCC takes place if we know from
`KnownBits` that LHS/RHS have the same sign.

The transform for LE/GE -> LT/GT takes place if LHS/RHS is constant
and we can inc/dec all elements in the operand without overflowing
(both signed and unsigned).

Alive2 Links (on i8 so they don't timeout):
sge_s:   https://alive2.llvm.org/ce/z/rMPt9_
sge_s_2: https://alive2.llvm.org/ce/z/G74Mhs
sge_u:   https://alive2.llvm.org/ce/z/PTWARM
sge_u_2: https://alive2.llvm.org/ce/z/L9dsNn
sgt_s:   https://alive2.llvm.org/ce/z/q2CHEK
sgt_u:   https://alive2.llvm.org/ce/z/YPLnZ8
sle_s:   https://alive2.llvm.org/ce/z/HyYhQ_
sle_s_2: https://alive2.llvm.org/ce/z/ck6NkT
sle_u:   https://alive2.llvm.org/ce/z/tyF_wN
sle_u_2: https://alive2.llvm.org/ce/z/et8t98
slt_s:   https://alive2.llvm.org/ce/z/oCP43b
slt_u:   https://alive2.llvm.org/ce/z/EpLLPx
uge_s:   https://alive2.llvm.org/ce/z/rqSDwi
uge_s_2: https://alive2.llvm.org/ce/z/67UTXu
uge_u:   https://alive2.llvm.org/ce/z/yBNG9C
uge_u_2: https://alive2.llvm.org/ce/z/UhHYc_
ugt_s:   https://alive2.llvm.org/ce/z/tY9va4
ugt_u:   https://alive2.llvm.org/ce/z/F9zeAT
ule_s:   https://alive2.llvm.org/ce/z/1MNgka
ule_s_2: https://alive2.llvm.org/ce/z/oiS7Ls
ule_u:   https://alive2.llvm.org/ce/z/8DveC3
ule_u_2: https://alive2.llvm.org/ce/z/jGp2M7
ult_s:   https://alive2.llvm.org/ce/z/chzfwP
ult_u:   https://alive2.llvm.org/ce/z/Jj_JYu

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D142254
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/urem-seteq-illegal-types.ll
llvm/test/CodeGen/X86/vector-compare-simplify.ll
llvm/test/CodeGen/X86/vector-popcnt-128-ult-ugt.ll
llvm/test/CodeGen/X86/vector-popcnt-256-ult-ugt.ll
llvm/test/CodeGen/X86/vector-popcnt-512-ult-ugt.ll