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
This commit is contained in:
Nate Begeman
2006-01-14 01:25:24 +00:00
parent 6283760cd1
commit 6fb3bd6a65
8 changed files with 113 additions and 9 deletions

View File

@@ -708,7 +708,8 @@ namespace {
static const char *DoesntAccessMemoryTable[] = {
// LLVM intrinsics:
"llvm.frameaddress", "llvm.returnaddress", "llvm.readport",
"llvm.isunordered", "llvm.sqrt", "llvm.ctpop", "llvm.ctlz", "llvm.cttz",
"llvm.isunordered", "llvm.sqrt", "llvm.bswap.i16", "llvm.bswap.i32",
"llvm.bswap.i64", "llvm.ctpop", "llvm.ctlz", "llvm.cttz",
"abs", "labs", "llabs", "imaxabs", "fabs", "fabsf", "fabsl",
"trunc", "truncf", "truncl", "ldexp",

View File

@@ -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])) {