diff options
author | Nate Begeman <natebegeman@mac.com> | 2006-01-14 01:25:24 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2006-01-14 01:25:24 +0000 |
commit | 6fb3bd6a658940287789198d3207b0da04c0a4e6 (patch) | |
tree | 7d3b9be2b6b00fd564f0b884de5c1999b1985890 /lib/Analysis/ConstantFolding.cpp | |
parent | 6283760cd13fa3f41c7f6462456661ea54ded980 (diff) |
Add bswap intrinsics as documented in the Language Reference
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 4022bdda1d..915a7cb734 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -37,6 +37,13 @@ llvm::canConstantFoldCallTo(Function *F) { switch (F->getIntrinsicID()) { case Intrinsic::isunordered: case Intrinsic::sqrt: + case Intrinsic::bswap_i16: + case Intrinsic::bswap_i32: + case Intrinsic::bswap_i64: + // FIXME: these should be constant folded as well + //case Intrinsic::ctpop: + //case Intrinsic::ctlz: + //case Intrinsic::cttz: return true; default: break; } @@ -142,6 +149,14 @@ llvm::ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands) { default: break; } + } else if (ConstantUInt *Op = dyn_cast<ConstantUInt>(Operands[0])) { + uint64_t V = Op->getValue(); + if (Name == "llvm.bswap.i16") + return ConstantUInt::get(Ty, ByteSwap_16(V)); + else if (Name == "llvm.bswap.i32") + return ConstantUInt::get(Ty, ByteSwap_32(V)); + else if (Name == "llvm.bswap.i64") + return ConstantUInt::get(Ty, ByteSwap_64(V)); } } else if (Operands.size() == 2) { if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) { |