llvm.org GIT mirror llvm / 6d5fc62
[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 Craig Topper 1 year, 10 months ago
3 changed file(s) with 26 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2929 // There is no need to change the IR, since backend will emit sqrt
3030 // instruction if the call has already been marked read-only.
3131 if (Call->onlyReadsMemory())
32 return false;
33
34 // The call must have the expected result type.
35 if (!Call->getType()->isFloatingPointTy())
3632 return false;
3733
3834 // Do the following transformation:
9591 if (!Call || !(CalledFunc = Call->getCalledFunction()))
9692 continue;
9793
94 if (Call->isNoBuiltin())
95 continue;
96
9897 // Skip if function either has local linkage or is not a known library
9998 // function.
10099 LibFunc LF;
101 if (CalledFunc->hasLocalLinkage() || !CalledFunc->hasName() ||
102 !TLI->getLibFunc(CalledFunc->getName(), LF))
100 if (CalledFunc->hasLocalLinkage() ||
101 !TLI->getLibFunc(*CalledFunc, LF) || !TLI->has(LF))
103102 continue;
104103
105104 switch (LF) {
33 target triple = "x86_64-unknown-linux-gnu"
44
55 declare i32 @sqrt()
6 declare float @sqrtf()
67
78 ; CHECK-LABEL: @foo
89 define i32 @foo() {
1112 %r = call i32 @sqrt()
1213 ret i32 %r
1314 }
15
16 ; CHECK-LABEL: @bar
17 define float @bar() {
18 ; CHECK: call{{.*}}@sqrtf
19 ; CHECK-NOT: call{{.*}}@sqrtf
20 %r = call float @sqrtf()
21 ret float %r
22 }
0 ; RUN: opt -S -partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
1 ; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2
3 define float @f(float %val) {
4 ; CHECK-LABEL: @f
5 ; CHECK: call{{.*}}@sqrtf
6 ; CHECK-NOT: call{{.*}}@sqrtf
7 %res = tail call float @sqrtf(float %val) nobuiltin
8 ret float %res
9 }
10
11 declare float @sqrtf(float)