summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp11
-rw-r--r--llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll9
-rw-r--r--llvm/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll12
3 files changed, 26 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index 1bfecea2f61..a044fe38b76 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -32,10 +32,6 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
if (Call->onlyReadsMemory())
return false;
- // The call must have the expected result type.
- if (!Call->getType()->isFloatingPointTy())
- return false;
-
// Do the following transformation:
//
// (before)
@@ -96,11 +92,14 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
if (!Call || !(CalledFunc = Call->getCalledFunction()))
continue;
+ if (Call->isNoBuiltin())
+ continue;
+
// Skip if function either has local linkage or is not a known library
// function.
LibFunc LF;
- if (CalledFunc->hasLocalLinkage() || !CalledFunc->hasName() ||
- !TLI->getLibFunc(CalledFunc->getName(), LF))
+ if (CalledFunc->hasLocalLinkage() ||
+ !TLI->getLibFunc(*CalledFunc, LF) || !TLI->has(LF))
continue;
switch (LF) {
diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
index e4d4cf7827a..78c192e8c5c 100644
--- a/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
@@ -4,6 +4,7 @@
target triple = "x86_64-unknown-linux-gnu"
declare i32 @sqrt()
+declare float @sqrtf()
; CHECK-LABEL: @foo
define i32 @foo() {
@@ -12,3 +13,11 @@ define i32 @foo() {
%r = call i32 @sqrt()
ret i32 %r
}
+
+; CHECK-LABEL: @bar
+define float @bar() {
+ ; CHECK: call{{.*}}@sqrtf
+ ; CHECK-NOT: call{{.*}}@sqrtf
+ %r = call float @sqrtf()
+ ret float %r
+}
diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll
new file mode 100644
index 00000000000..c648ce07cf5
--- /dev/null
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll
@@ -0,0 +1,12 @@
+; RUN: opt -S -partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define float @f(float %val) {
+; CHECK-LABEL: @f
+; CHECK: call{{.*}}@sqrtf
+; CHECK-NOT: call{{.*}}@sqrtf
+ %res = tail call float @sqrtf(float %val) nobuiltin
+ ret float %res
+}
+
+declare float @sqrtf(float)
OpenPOWER on IntegriCloud