Improve an integer select optimization in two ways:
authorChris Lattner <sabre@nondot.org>
Sun, 5 Dec 2010 01:23:24 +0000 (01:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 5 Dec 2010 01:23:24 +0000 (01:23 +0000)
commita2b5600e615feb71840cd66d2676a8938daf737e
tree247ba28bda16836745daaeb67a37d50b6248262f
parentbced6a1b8f10e5a3720e376d4ad0850c5165e45f
Improve an integer select optimization in two ways:

1. generalize
    (select (x == 0), -1, 0) -> (sign_bit (x - 1))
to:
    (select (x == 0), -1, y) -> (sign_bit (x - 1)) | y

2. Handle the identical pattern that happens with !=:
   (select (x != 0), y, -1) -> (sign_bit (x - 1)) | y

cmov is often high latency and can't fold immediates or
memory operands.  For example for (x == 0) ? -1 : 1, before
we got:

<  testb %sil, %sil
<  movl $-1, %ecx
<  movl $1, %eax
<  cmovel %ecx, %eax

now we get:

>  cmpb $1, %sil
>  sbbl %eax, %eax
>  orl $1, %eax

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