[llvm-commits] [llvm] r123547 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Sat Jan 15 18:51:57 PST 2011
On Jan 15, 2011, at 5:02 PM, Chris Lattner wrote:
> One major advantage of recognizing popcount though is that the optimizer has a chance of hacking on it, and there are a lot of instcombine xforms that we could do. Here are some that I note looking at the bc file for crafy (when hacked to use builtin_popcount). I attached the bc file below if you're interested.
I noticed that we have intrinsics and ISD nodes for ctlz, cttz, and ctpop, but none for parity. Is that on purpose?
Currently, clang compiles __builtin_parity to:
define i32 @f(i32 %x) nounwind readnone ssp {
entry:
%tmp1 = tail call i32 @llvm.ctpop.i32(i32 %x)
%tmp2 = and i32 %tmp1, 1
ret i32 %tmp2
}
With corresponding horrible codegen on x86. The IR would be fine for a target with a POPCNT instruction and no parity, but it is much cheaper to compute just the parity when you don't have a POPCNT.
You want something like:
x ^= x >> 16;
x ^= x >> 8;
return parity_bit(eflags);
Or portably in compiler-rt:
si_int
__paritysi2(si_int a)
{
su_int x = (su_int)a;
x ^= x >> 16;
x ^= x >> 8;
x ^= x >> 4;
return (0x6996 >> (x & 0xF)) & 1;
}
/jakob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110115/394310a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110115/394310a5/attachment.bin>
More information about the llvm-commits
mailing list