aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-07-19 08:09:34 +0000
committerOwen Anderson <resistor@mac.com>2010-07-19 08:09:34 +0000
commitd90290127b48f1135547956c6131883d905a71b6 (patch)
tree99d5cfc180a436118c18f5b76ac53a4673790325 /lib/Transforms/InstCombine/InstCombineCasts.cpp
parent926f2bb3d8dd6f8b0198aa478828ee02914050f9 (diff)
Reimplement r108639 in InstCombine rather than DAGCombine.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108687 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCasts.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 505a0bf8f4..042bf1a982 100644
--- a/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1097,6 +1097,32 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
break;
}
}
+
+ // Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
+ // NOTE: This should be disabled by -fno-builtin-sqrt if we ever support it.
+ CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
+ if (Call && Call->getCalledFunction() &&
+ Call->getCalledFunction()->getName() == "sqrt" &&
+ Call->getNumArgOperands() == 1) {
+ CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
+ if (Arg && Arg->getOpcode() == Instruction::FPExt &&
+ CI.getType() == Builder->getFloatTy() &&
+ Call->getType() == Builder->getDoubleTy() &&
+ Arg->getType() == Builder->getDoubleTy() &&
+ Arg->getOperand(0)->getType() == Builder->getFloatTy()) {
+ Module* M = CI.getParent()->getParent()->getParent();
+ Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf",
+ Call->getAttributes(),
+ Builder->getFloatTy(),
+ Builder->getFloatTy(),
+ NULL);
+ CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
+ "sqrtfcall");
+ ret->setAttributes(Call->getAttributes());
+ return ret;
+ }
+ }
+
return 0;
}