Currently we only create KTEST with the same argument twice. We don't try to find any ANDs or ORs.
This patch changes lowering to produce X86ISD::KTESTREG which represents just the flag setting behavior of KTEST/KORTEST. We now use this where we previously duplicated the operand. Isel now has patterns to look for this node with and/or to create KTEST/KORTEST. If we fail to match that, just fail back to using a KORTEST with both operands the same. KORTEST is chosen because KORTESTW is available in avx512f while KTESTW requires avx512dq.
This also updates the KORTEST intrinsic lowering to use an OR+X86ISD::KTESTREG. I'll probably look into changing the builtin to create the or+bitcast+icmp in clang and deprecrate the backend intrinsic.