Add support for sqrt, sqrtl, and sqrtf in TargetLibraryInfo. Disable

(fptrunc (sqrt (fpext x))) -> (sqrtf x) transformation if -fno-builtin is 
specified.
rdar://10466410

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145460 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chad Rosier
2011-11-29 23:57:10 +00:00
parent 6029b6ddaf
commit 3d925d24e8
5 changed files with 35 additions and 3 deletions

View File

@ -14,6 +14,7 @@
#include "InstCombine.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Support/PatternMatch.h"
using namespace llvm;
using namespace PatternMatch;
@ -1213,10 +1214,10 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
}
// Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
// NOTE: This should be disabled by -fno-builtin-sqrt if we ever support it.
const TargetLibraryInfo &TLI = getAnalysis<TargetLibraryInfo>();
CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
if (Call && Call->getCalledFunction() &&
Call->getCalledFunction()->getName() == "sqrt" &&
if (Call && Call->getCalledFunction() && TLI.has(LibFunc::sqrtf) &&
Call->getCalledFunction()->getName() == TLI.getName(LibFunc::sqrt) &&
Call->getNumArgOperands() == 1 &&
Call->hasOneUse()) {
CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));