Constant fold llvm.sqrt

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23487 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-09-28 01:34:32 +00:00
parent 5b3c70263b
commit 32643d8e05

View File

@ -240,7 +240,9 @@ bool llvm::canConstantFoldCallTo(Function *F) {
const std::string &Name = F->getName();
switch (F->getIntrinsicID()) {
case Intrinsic::isunordered: return true;
case Intrinsic::isunordered:
case Intrinsic::sqrt:
return true;
default: break;
}
@ -321,6 +323,12 @@ Constant *llvm::ConstantFoldCall(Function *F,
return ConstantFP::get(Ty, log(V));
else if (Name == "log10" && V > 0)
return ConstantFoldFP(log10, V, Ty);
else if (Name == "llvm.sqrt") {
if (V >= -0.0)
return ConstantFP::get(Ty, sqrt(V));
else // Undefined
return ConstantFP::get(Ty, 0.0);
}
break;
case 's':
if (Name == "sin")