OSDN Git Service

[X86] Don't emit KTEST instructions unless only the Z flag is being used
authorCraig Topper <craig.topper@intel.com>
Thu, 8 Feb 2018 07:45:55 +0000 (07:45 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 8 Feb 2018 07:45:55 +0000 (07:45 +0000)
commit181057ed1fc0d854490bad47bc76df63578a8c16
tree31a3b24f5078fe5b99bcf5a18489a47f5690434e
parent97f86a9714e2eca765bec8e659246f10d2e38117
[X86] Don't emit KTEST instructions unless only the Z flag is being used

Summary:
KTEST has weird flag behavior. The Z flag is set for all bits in the AND of the k-registers being 0, and the C flag is set for all bits being 1. All other flags are cleared.

We currently emit this instruction in EmitTEST and don't check the condition code. This can lead to strange things like using the S flag after a KTEST for a signed compare.

The domain reassignment pass can also transform TEST instructions into KTEST and is not protected against the flag usage either. For now I've disabled this part of the domain reassignment pass. I tried to comment out the checks in the mir test so that we could recover them later, but I couldn't figure out how to get that to work.

This patch moves the KTEST handling into LowerSETCC and now creates a ktest+x86setcc. I've chosen this approach because I'd like to add support for the C flag for all ones in a followup patch. To do that requires that I can rewrite the condition code going in the x86setcc to be different than the original SETCC condition code.

This fixes PR36182. I'll file a PR to fix domain reassignment once this goes in. Should this be merged to 6.0?

Reviewers: spatel, guyblank, RKSimon, zvi

Reviewed By: guyblank

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D42770

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324576 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86DomainReassignment.cpp
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/avx512-mask-op.ll
test/CodeGen/X86/domain-reassignment.mir