diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-04-01 07:35:23 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-04-01 07:35:23 +0000 |
commit | e9391fd9b52e93717b365bdd05c471101323a4df (patch) | |
tree | 1fcb5a6142634e5234ae8bc858d800e96eb24785 /lib/Analysis/ConstantFolding.cpp | |
parent | a4f9c4d29affaae0b4a3315ffff20e9130ecd17f (diff) |
For PR1297:
Support overloaded intrinsics bswap, ctpop, cttz, ctlz.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 1288674139..f0bd1dd0ad 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -317,24 +317,12 @@ llvm::canConstantFoldCallTo(Function *F) { 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 @@ llvm::ConstantFoldCall(Function *F, Constant** Operands, unsigned NumOperands) { 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])) { |