[llvm-commits] [llvm] r145460 - in /llvm/trunk: include/llvm/Target/TargetLibraryInfo.h lib/Target/TargetLibraryInfo.cpp lib/Transforms/InstCombine/InstCombineCasts.cpp lib/Transforms/InstCombine/InstructionCombining.cpp test/Transforms/InstCombine/fold-sqrt-sqrtf.ll
Chad Rosier
mcrosier at apple.com
Tue Nov 29 15:57:10 PST 2011
Author: mcrosier
Date: Tue Nov 29 17:57:10 2011
New Revision: 145460
URL: http://llvm.org/viewvc/llvm-project?rev=145460&view=rev
Log:
Add support for sqrt, sqrtl, and sqrtf in TargetLibraryInfo. Disable
(fptrunc (sqrt (fpext x))) -> (sqrtf x) transformation if -fno-builtin is
specified.
rdar://10466410
Added:
llvm/trunk/test/Transforms/InstCombine/fold-sqrt-sqrtf.ll
Modified:
llvm/trunk/include/llvm/Target/TargetLibraryInfo.h
llvm/trunk/lib/Target/TargetLibraryInfo.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
Modified: llvm/trunk/include/llvm/Target/TargetLibraryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLibraryInfo.h?rev=145460&r1=145459&r2=145460&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLibraryInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLibraryInfo.h Tue Nov 29 17:57:10 2011
@@ -35,6 +35,15 @@
/// int siprintf(char *str, const char *format, ...);
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, ...);
fiprintf,
Modified: llvm/trunk/lib/Target/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLibraryInfo.cpp?rev=145460&r1=145459&r2=145460&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetLibraryInfo.cpp Tue Nov 29 17:57:10 2011
@@ -28,6 +28,9 @@
"memset_pattern16",
"iprintf",
"siprintf",
+ "sqrt",
+ "sqrtl",
+ "sqrtf",
"fiprintf",
"fwrite",
"fputs"
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=145460&r1=145459&r2=145460&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Nov 29 17:57:10 2011
@@ -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 @@
}
// 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));
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=145460&r1=145459&r2=145460&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue Nov 29 17:57:10 2011
@@ -41,6 +41,7 @@
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetLibraryInfo.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Debug.h"
@@ -79,6 +80,7 @@
void InstCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
+ AU.addRequired<TargetLibraryInfo>();
}
Added: llvm/trunk/test/Transforms/InstCombine/fold-sqrt-sqrtf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fold-sqrt-sqrtf.ll?rev=145460&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fold-sqrt-sqrtf.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/fold-sqrt-sqrtf.ll Tue Nov 29 17:57:10 2011
@@ -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)
More information about the llvm-commits
mailing list