summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine
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
commit32a58342eda5cbe11dc3e75cf0075e4a1ca16d9a (patch)
tree6aded05da10baa422cd44fc04d551f51230f0fc7 /llvm/lib/Transforms/InstCombine
parent00c57967da0be457471092fbd87518433a1862c6 (diff)
downloadbcm5719-llvm-32a58342eda5cbe11dc3e75cf0075e4a1ca16d9a.tar.gz
bcm5719-llvm-32a58342eda5cbe11dc3e75cf0075e4a1ca16d9a.zip
Reimplement r108639 in InstCombine rather than DAGCombine.
llvm-svn: 108687
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 505a0bf8f4e..042bf1a9829 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud