mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
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:
@ -35,6 +35,15 @@ namespace llvm {
|
|||||||
|
|
||||||
/// int siprintf(char *str, const char *format, ...);
|
/// int siprintf(char *str, const char *format, ...);
|
||||||
siprintf,
|
siprintf,
|
||||||
|
|
||||||
|
/// double sqrt(double x);
|
||||||
|
sqrt,
|
||||||
|
|
||||||
|
/// long double sqrtl(long double x);
|
||||||
|
sqrtl,
|
||||||
|
|
||||||
|
/// float sqrtf(float x);
|
||||||
|
sqrtf,
|
||||||
|
|
||||||
/// int fiprintf(FILE *stream, const char *format, ...);
|
/// int fiprintf(FILE *stream, const char *format, ...);
|
||||||
fiprintf,
|
fiprintf,
|
||||||
|
@ -28,6 +28,9 @@ const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
|
|||||||
"memset_pattern16",
|
"memset_pattern16",
|
||||||
"iprintf",
|
"iprintf",
|
||||||
"siprintf",
|
"siprintf",
|
||||||
|
"sqrt",
|
||||||
|
"sqrtl",
|
||||||
|
"sqrtf",
|
||||||
"fiprintf",
|
"fiprintf",
|
||||||
"fwrite",
|
"fwrite",
|
||||||
"fputs"
|
"fputs"
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "InstCombine.h"
|
#include "InstCombine.h"
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
#include "llvm/Support/PatternMatch.h"
|
#include "llvm/Support/PatternMatch.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace PatternMatch;
|
using namespace PatternMatch;
|
||||||
@ -1213,10 +1214,10 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fold (fptrunc (sqrt (fpext x))) -> (sqrtf x)
|
// 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));
|
CallInst *Call = dyn_cast<CallInst>(CI.getOperand(0));
|
||||||
if (Call && Call->getCalledFunction() &&
|
if (Call && Call->getCalledFunction() && TLI.has(LibFunc::sqrtf) &&
|
||||||
Call->getCalledFunction()->getName() == "sqrt" &&
|
Call->getCalledFunction()->getName() == TLI.getName(LibFunc::sqrt) &&
|
||||||
Call->getNumArgOperands() == 1 &&
|
Call->getNumArgOperands() == 1 &&
|
||||||
Call->hasOneUse()) {
|
Call->hasOneUse()) {
|
||||||
CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
|
CastInst *Arg = dyn_cast<CastInst>(Call->getArgOperand(0));
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "llvm/Analysis/InstructionSimplify.h"
|
#include "llvm/Analysis/InstructionSimplify.h"
|
||||||
#include "llvm/Analysis/MemoryBuiltins.h"
|
#include "llvm/Analysis/MemoryBuiltins.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetLibraryInfo.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
@ -79,6 +80,7 @@ INITIALIZE_PASS(InstCombiner, "instcombine",
|
|||||||
|
|
||||||
void InstCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
|
void InstCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
|
AU.addRequired<TargetLibraryInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
17
test/Transforms/InstCombine/fold-sqrt-sqrtf.ll
Normal file
17
test/Transforms/InstCombine/fold-sqrt-sqrtf.ll
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
; RUN: opt -instcombine -S -disable-simplify-libcalls < %s | FileCheck %s
|
||||||
|
; rdar://10466410
|
||||||
|
|
||||||
|
; Instcombine tries to fold (fptrunc (sqrt (fpext x))) -> (sqrtf x), but this
|
||||||
|
; shouldn't fold when sqrtf isn't available.
|
||||||
|
define float @foo(float %f) uwtable ssp {
|
||||||
|
entry:
|
||||||
|
; CHECK: %conv = fpext float %f to double
|
||||||
|
; CHECK: %call = tail call double @sqrt(double %conv)
|
||||||
|
; CHECK: %conv1 = fptrunc double %call to float
|
||||||
|
%conv = fpext float %f to double
|
||||||
|
%call = tail call double @sqrt(double %conv)
|
||||||
|
%conv1 = fptrunc double %call to float
|
||||||
|
ret float %conv1
|
||||||
|
}
|
||||||
|
|
||||||
|
declare double @sqrt(double)
|
Reference in New Issue
Block a user