Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 6d5fc62

Browse files
committed
[PartialInlineLibCalls] Teach PartialInlineLibCalls to honor nobuiltin, properly check the function signature, and check TLI::has
Summary: We shouldn't do this transformation if the function is marked nobuitlin. We were only checking that the return type is floating point, we really should be checking the argument types and argument count as well. This can be accomplished by using the other version of getLibFunc that takes the Function and not just the name. We should also be checking TLI::has since sqrtf is a macro on Windows. Fixes PR32559. Reviewers: hfinkel, spatel, davide, efriedma Reviewed By: davide, efriedma Subscribers: efriedma, llvm-commits, eraman Differential Revision: https://reviews.llvm.org/D39381 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316819 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b35e220 commit 6d5fc62

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
3232
if (Call->onlyReadsMemory())
3333
return false;
3434

35-
// The call must have the expected result type.
36-
if (!Call->getType()->isFloatingPointTy())
37-
return false;
38-
3935
// Do the following transformation:
4036
//
4137
// (before)
@@ -96,11 +92,14 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
9692
if (!Call || !(CalledFunc = Call->getCalledFunction()))
9793
continue;
9894

95+
if (Call->isNoBuiltin())
96+
continue;
97+
9998
// Skip if function either has local linkage or is not a known library
10099
// function.
101100
LibFunc LF;
102-
if (CalledFunc->hasLocalLinkage() || !CalledFunc->hasName() ||
103-
!TLI->getLibFunc(CalledFunc->getName(), LF))
101+
if (CalledFunc->hasLocalLinkage() ||
102+
!TLI->getLibFunc(*CalledFunc, LF) || !TLI->has(LF))
104103
continue;
105104

106105
switch (LF) {

test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
target triple = "x86_64-unknown-linux-gnu"
55

66
declare i32 @sqrt()
7+
declare float @sqrtf()
78

89
; CHECK-LABEL: @foo
910
define i32 @foo() {
@@ -12,3 +13,11 @@ define i32 @foo() {
1213
%r = call i32 @sqrt()
1314
ret i32 %r
1415
}
16+
17+
; CHECK-LABEL: @bar
18+
define float @bar() {
19+
; CHECK: call{{.*}}@sqrtf
20+
; CHECK-NOT: call{{.*}}@sqrtf
21+
%r = call float @sqrtf()
22+
ret float %r
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: opt -S -partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2+
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
define float @f(float %val) {
5+
; CHECK-LABEL: @f
6+
; CHECK: call{{.*}}@sqrtf
7+
; CHECK-NOT: call{{.*}}@sqrtf
8+
%res = tail call float @sqrtf(float %val) nobuiltin
9+
ret float %res
10+
}
11+
12+
declare float @sqrtf(float)

0 commit comments

Comments
 (0)