[PATCH] D39381: [PartialInlineLibCalls] Teach PartialInlineLibCalls to honor nobuiltin, properly check the function signature, and check TLI::has

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 12:47:07 PDT 2017


craig.topper created this revision.
Herald added a subscriber: eraman.

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.

Happy to split this up if we want.

Fixes PR32559.


https://reviews.llvm.org/D39381

Files:
  lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
  test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
  test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll


Index: test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll
===================================================================
--- /dev/null
+++ 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)
Index: test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
===================================================================
--- test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
+++ test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
@@ -4,11 +4,20 @@
 target triple = "x86_64-unknown-linux-gnu"
 
 declare i32 @sqrt()
+declare float @sqrtf()
 
 ; CHECK-LABEL: @foo
 define i32 @foo() {
   ; CHECK: call{{.*}}@sqrt
   ; CHECK-NOT: call{{.*}}@sqrt
   %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
+}
Index: lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
===================================================================
--- lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -32,10 +32,6 @@
   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 @@
       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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39381.120677.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171027/623b688b/attachment.bin>


More information about the llvm-commits mailing list