const std::string &Name = F->getName();
switch (F->getIntrinsicID()) {
- case Intrinsic::isunordered_f32:
- case Intrinsic::isunordered_f64:
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:
}
}
-Constant *
-llvm::ConstantFoldFP(double (*NativeFP)(double), double V, const Type *Ty) {
+static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
+ const Type *Ty) {
errno = 0;
V = NativeFP(V);
if (errno == 0)
return ConstantFP::get(Ty, V);
+ errno = 0;
return 0;
}
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
/// with the specified arguments, returning null if unsuccessful.
Constant *
-llvm::ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands) {
+llvm::ConstantFoldCall(Function *F, Constant** Operands, unsigned NumOperands) {
const std::string &Name = F->getName();
const Type *Ty = F->getReturnType();
- if (Operands.size() == 1) {
+ if (NumOperands == 1) {
if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) {
double V = Op->getValue();
switch (Name[0])
default:
break;
}
- } else if (ConstantUInt *Op = dyn_cast<ConstantUInt>(Operands[0])) {
- uint64_t V = Op->getValue();
+ } else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
+ uint64_t V = Op->getZExtValue();
if (Name == "llvm.bswap.i16")
- return ConstantUInt::get(Ty, ByteSwap_16(V));
+ return ConstantInt::get(Ty, ByteSwap_16(V));
else if (Name == "llvm.bswap.i32")
- return ConstantUInt::get(Ty, ByteSwap_32(V));
+ return ConstantInt::get(Ty, ByteSwap_32(V));
else if (Name == "llvm.bswap.i64")
- return ConstantUInt::get(Ty, ByteSwap_64(V));
+ return ConstantInt::get(Ty, ByteSwap_64(V));
}
- } else if (Operands.size() == 2) {
+ } else if (NumOperands == 2) {
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
double Op1V = Op1->getValue();
if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) {
double Op2V = Op2->getValue();
- if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64")
- return ConstantBool::get(IsNAN(Op1V) || IsNAN(Op2V));
- else
if (Name == "pow") {
errno = 0;
double V = pow(Op1V, Op2V);
double V = fmod(Op1V, Op2V);
if (errno == 0)
return ConstantFP::get(Ty, V);
- } else if (Name == "atan2")
+ } else if (Name == "atan2") {
return ConstantFP::get(Ty, atan2(Op1V,Op2V));
+ }
+ } else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) {
+ if (Name == "llvm.powi.f32") {
+ return ConstantFP::get(Ty, std::pow((float)Op1V,
+ (int)Op2C->getZExtValue()));
+ } else if (Name == "llvm.powi.f64") {
+ return ConstantFP::get(Ty, std::pow((double)Op1V,
+ (int)Op2C->getZExtValue()));
+ }
}
}
}