Changes in directory llvm/lib/Analysis:
ConstantFolding.cpp updated: 1.20 -> 1.21 --- Log message: For PR1297: http://llvm.org/PR1297 : Support overloaded intrinsics bswap, ctpop, cttz, ctlz. --- Diffs of the changes: (+17 -23) ConstantFolding.cpp | 40 +++++++++++++++++----------------------- 1 files changed, 17 insertions(+), 23 deletions(-) Index: llvm/lib/Analysis/ConstantFolding.cpp diff -u llvm/lib/Analysis/ConstantFolding.cpp:1.20 llvm/lib/Analysis/ConstantFolding.cpp:1.21 --- llvm/lib/Analysis/ConstantFolding.cpp:1.20 Sun Mar 4 18:00:41 2007 +++ llvm/lib/Analysis/ConstantFolding.cpp Sun Apr 1 02:35:23 2007 @@ -317,24 +317,12 @@ switch (F->getIntrinsicID()) { case Intrinsic::sqrt_f32: case Intrinsic::sqrt_f64: - case Intrinsic::bswap_i16: - case Intrinsic::bswap_i32: - case Intrinsic::bswap_i64: case Intrinsic::powi_f32: case Intrinsic::powi_f64: - // FIXME: these should be constant folded as well - //case Intrinsic::ctpop_i8: - //case Intrinsic::ctpop_i16: - //case Intrinsic::ctpop_i32: - //case Intrinsic::ctpop_i64: - //case Intrinsic::ctlz_i8: - //case Intrinsic::ctlz_i16: - //case Intrinsic::ctlz_i32: - //case Intrinsic::ctlz_i64: - //case Intrinsic::cttz_i8: - //case Intrinsic::cttz_i16: - //case Intrinsic::cttz_i32: - //case Intrinsic::cttz_i64: + case Intrinsic::bswap: + case Intrinsic::ctpop: + case Intrinsic::ctlz: + case Intrinsic::cttz: return true; default: break; } @@ -445,13 +433,19 @@ break; } } else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) { - uint64_t V = Op->getZExtValue(); - if (Name == "llvm.bswap.i16") - return ConstantInt::get(Ty, ByteSwap_16(V)); - else if (Name == "llvm.bswap.i32") - return ConstantInt::get(Ty, ByteSwap_32(V)); - else if (Name == "llvm.bswap.i64") - return ConstantInt::get(Ty, ByteSwap_64(V)); + const IntegerType *OpTy = cast<IntegerType>(Op->getType()); + if (Name.size() > 11 && !memcmp(&Name[0], "llvm.bswap", 10)) { + return ConstantInt::get(Op->getValue().byteSwap()); + } else if (Name.size() > 11 && !memcmp(&Name[0],"llvm.ctpop",10)) { + uint64_t ctpop = Op->getValue().countPopulation(); + return ConstantInt::get(OpTy, ctpop); + } else if (Name.size() > 10 && !memcmp(&Name[0], "llvm.cttz", 9)) { + uint64_t cttz = Op->getValue().countTrailingZeros(); + return ConstantInt::get(OpTy, cttz); + } else if (Name.size() > 10 && !memcmp(&Name[0], "llvm.ctlz", 9)) { + uint64_t ctlz = Op->getValue().countLeadingZeros(); + return ConstantInt::get(OpTy, ctlz); + } } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) { _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits