[llvm-commits] CVS: llvm/lib/CodeGen/IntrinsicLowering.cpp
Zhou Sheng
zhousheng00 at gmail.com
Fri Jun 1 21:10:55 PDT 2007
Changes in directory llvm/lib/CodeGen:
IntrinsicLowering.cpp updated: 1.85 -> 1.86
---
Log message:
Make LowerCTPOP() support arbitrary bitwidth integer type.
---
Diffs of the changes: (+22 -9)
IntrinsicLowering.cpp | 31 ++++++++++++++++++++++---------
1 files changed, 22 insertions(+), 9 deletions(-)
Index: llvm/lib/CodeGen/IntrinsicLowering.cpp
diff -u llvm/lib/CodeGen/IntrinsicLowering.cpp:1.85 llvm/lib/CodeGen/IntrinsicLowering.cpp:1.86
--- llvm/lib/CodeGen/IntrinsicLowering.cpp:1.85 Fri May 25 22:43:13 2007
+++ llvm/lib/CodeGen/IntrinsicLowering.cpp Fri Jun 1 23:10:33 2007
@@ -208,17 +208,30 @@
};
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
+ unsigned WordSize = (BitSize + 63) / 64;
+ Value *Count = ConstantInt::get(V->getType(), 0);
- for (unsigned i = 1, ct = 0; i != BitSize; i <<= 1, ++ct) {
- Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
- Value *LHS = BinaryOperator::createAnd(V, MaskCst, "cppop.and1", IP);
- Value *VShift = BinaryOperator::createLShr(V,
- ConstantInt::get(V->getType(), i), "ctpop.sh", IP);
- Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP);
- V = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP);
+ for (unsigned n = 0; n < WordSize; ++n) {
+ Value *PartValue = V;
+ for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
+ i <<= 1, ++ct) {
+ Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
+ Value *LHS = BinaryOperator::createAnd(
+ PartValue, MaskCst, "cppop.and1", IP);
+ Value *VShift = BinaryOperator::createLShr(PartValue,
+ ConstantInt::get(V->getType(), i), "ctpop.sh", IP);
+ Value *RHS = BinaryOperator::createAnd(VShift, MaskCst, "cppop.and2", IP);
+ PartValue = BinaryOperator::createAdd(LHS, RHS, "ctpop.step", IP);
+ }
+ Count = BinaryOperator::createAdd(PartValue, Count, "ctpop.part", IP);
+ if (BitSize > 64) {
+ V = BinaryOperator::createLShr(V, ConstantInt::get(V->getType(), 64),
+ "ctpop.part.sh", IP);
+ BitSize -= 64;
+ }
}
- return CastInst::createIntegerCast(V, Type::Int32Ty, false, "ctpop", IP);
+ return CastInst::createIntegerCast(Count, Type::Int32Ty, false, "ctpop", IP);
}
/// LowerCTLZ - Emit the code to lower ctlz of V before the specified
@@ -226,7 +239,7 @@
static Value *LowerCTLZ(Value *V, Instruction *IP) {
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
- for (unsigned i = 1; i != BitSize; i <<= 1) {
+ for (unsigned i = 1; i < BitSize; i <<= 1) {
Value *ShVal = ConstantInt::get(V->getType(), i);
ShVal = BinaryOperator::createLShr(V, ShVal, "ctlz.sh", IP);
V = BinaryOperator::createOr(V, ShVal, "ctlz.step", IP);
More information about the llvm-commits
mailing list