[llvm] r316819 - [PartialInlineLibCalls] Teach PartialInlineLibCalls to honor nobuiltin, properly check the function signature, and check TLI::has

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 17:36:58 PDT 2017


Author: ctopper
Date: Fri Oct 27 17:36:58 2017
New Revision: 316819

URL: http://llvm.org/viewvc/llvm-project?rev=316819&view=rev
Log:
[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

Added:
    llvm/trunk/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
    llvm/trunk/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll

Modified: llvm/trunk/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp?rev=316819&r1=316818&r2=316819&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp Fri Oct 27 17:36:58 2017
@@ -32,10 +32,6 @@ static bool optimizeSQRT(CallInst *Call,
   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(F
       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) {

Modified: llvm/trunk/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll?rev=316819&r1=316818&r2=316819&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll (original)
+++ llvm/trunk/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll Fri Oct 27 17:36:58 2017
@@ -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
+}

Added: llvm/trunk/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll?rev=316819&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll (added)
+++ llvm/trunk/test/Transforms/PartiallyInlineLibCalls/nobuiltin.ll Fri Oct 27 17:36:58 2017
@@ -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)




More information about the llvm-commits mailing list