]> granicus.if.org Git - llvm/commit
[X86] The TEST instruction is eliminated when BSF/TZCNT is used
authorCraig Topper <craig.topper@intel.com>
Wed, 11 Jul 2018 06:57:42 +0000 (06:57 +0000)
committerCraig Topper <craig.topper@intel.com>
Wed, 11 Jul 2018 06:57:42 +0000 (06:57 +0000)
commit002bef1dc82fe5e46b789efd427f76de7f97104c
tree9c949a4959ed82c4972f0a34b349d0de58997b66
parentbcf1a2ec72da9b9b1f2710100d00c7a175dc35de
[X86] The TEST instruction is eliminated when BSF/TZCNT is used

Summary:
These changes cover the PR#31399.
Now the ffs(x) function is lowered to (x != 0) ? llvm.cttz(x) + 1 : 0
and it corresponds to the following llvm code:
  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
  %tobool = icmp eq i32 %v, 0
  %.op = add nuw nsw i32 %cnt, 1
  %add = select i1 %tobool, i32 0, i32 %.op
and x86 asm code:
  bsfl     %edi, %ecx
  addl     $1, %ecx
  testl    %edi, %edi
  movl     $0, %eax
  cmovnel  %ecx, %eax
In this case the 'test' instruction can't be eliminated because
the 'add' instruction modifies the EFLAGS, namely, ZF flag
that is set by the 'bsf' instruction when 'x' is zero.

We now produce the following code:
  bsfl     %edi, %ecx
  movl     $-1, %eax
  cmovnel  %ecx, %eax
  addl     $1, %eax

Patch by Ivan Kulagin

Reviewers: davide, craig.topper, spatel, RKSimon

Reviewed By: craig.topper

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336768 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.cpp
test/CodeGen/X86/dagcombine-select.ll