Use standard promotion for i8 CTTZ nodes and i8 CTLZ nodes when the
authorChandler Carruth <chandlerc@gmail.com>
Sat, 24 Dec 2011 12:12:34 +0000 (12:12 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 24 Dec 2011 12:12:34 +0000 (12:12 +0000)
commit7782102c70fdfd48776f05099eb67dd268cfc222
treebfdaa8f63ef7445489f0568106f80b7c1829e701
parent3d636ea8edf9332ab5ab2d92f7ea5c7444e88757
Use standard promotion for i8 CTTZ nodes and i8 CTLZ nodes when the
LZCNT instructions are available. Force promotion to i32 to get
a smaller encoding since the fix-ups necessary are just as complex for
either promoted type

We can't do standard promotion for CTLZ when lowering through BSR
because it results in poor code surrounding the 'xor' at the end of this
instruction. Essentially, if we promote the entire CTLZ node to i32, we
end up doing the xor on a 32-bit CTLZ implementation, and then
subtracting appropriately to get back to an i8 value. Instead, our
custom logic just uses the knowledge of the incoming size to compute
a perfect xor. I'd love to know of a way to fix this, but so far I'm
drawing a blank. I suspect the legalizer could be more clever and/or it
could collude with the DAG combiner, but how... ;]

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