[X86][SSE] Handle basic inversion of PTEST/TESTP operands (PR38522)
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 1 Apr 2020 09:56:36 +0000 (10:56 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 1 Apr 2020 10:33:28 +0000 (11:33 +0100)
commit918ccb64b02281355a6226fe8af07dc40e8ff9e3
tree4aefb353b41e7eb624d2686532e87cf090a87717
parent8b8cd150a4a176cd971c604f92de76acdae4a301
[X86][SSE] Handle basic inversion of PTEST/TESTP operands (PR38522)

PTEST/TESTP sets EFLAGS as:
TESTZ: ZF = (Op0 & Op1) == 0
TESTC: CF = (~Op0 & Op1) == 0
TESTNZC: ZF == 0 && CF == 0

If we are inverting the 0'th operand of a PTEST/TESTP instruction we can adjust the comparisons to correct handle the inversion implicitly.

Additionally, for "TESTZ" (ZF) cases, the allones case, PTEST(X,-1) can be simplified to PTEST(X,X).

We can expand this for the TESTZ(X,~Y) pattern and also handle KTEST/KORTEST in the future.

Differential Revision: https://reviews.llvm.org/D76984
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-ptest.ll
llvm/test/CodeGen/X86/combine-testpd.ll
llvm/test/CodeGen/X86/combine-testps.ll