[PATCH] D42770: [X86] Don't emit KTEST instructions unless only the Z flag is being used

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 16:38:46 PST 2018


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

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?


https://reviews.llvm.org/D42770

Files:
  lib/Target/X86/X86DomainReassignment.cpp
  lib/Target/X86/X86ISelLowering.cpp
  test/CodeGen/X86/avx512-mask-op.ll
  test/CodeGen/X86/domain-reassignment.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42770.132294.patch
Type: text/x-patch
Size: 9234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180201/3f7d96f4/attachment.bin>


More information about the llvm-commits mailing list