InstCombine: Turn icmp + sext into bitwise/integer ops when the input has only one...
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 1 Apr 2011 20:09:10 +0000 (20:09 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 1 Apr 2011 20:09:10 +0000 (20:09 +0000)
commit0baa94a13bf24cf7d916b4c6c415fb84b464bfd3
tree5d431ec7da7f78c86da8b42e2f2733f412066b93
parent0a30c42008f88c3fba64127da8d73ba2fcd16fd6
InstCombine: Turn icmp + sext into bitwise/integer ops when the input has only one unknown bit.

int test1(unsigned x) { return (x&8) ? 0 : -1; }
int test3(unsigned x) { return (x&8) ? -1 : 0; }

before (x86_64):
_test1:
andl $8, %edi
cmpl $1, %edi
sbbl %eax, %eax
ret
_test3:
andl $8, %edi
cmpl $1, %edi
sbbl %eax, %eax
notl %eax
ret

after:
_test1:
shrl $3, %edi
andl $1, %edi
leal -1(%rdi), %eax
ret
_test3:
shll $28, %edi
movl %edi, %eax
sarl $31, %eax
ret

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128732 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCasts.cpp
test/Transforms/InstCombine/sext.ll