[llvm] 019e7b7 - [PartiallyInlineLibCalls] Don't partially inline a musttail libcall.

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 12:31:00 PDT 2022


Author: Bert Abrath
Date: 2022-04-05T22:30:50+03:00
New Revision: 019e7b7f6ed259296d04d9bc1550ea2898f48ec7

URL: https://github.com/llvm/llvm-project/commit/019e7b7f6ed259296d04d9bc1550ea2898f48ec7
DIFF: https://github.com/llvm/llvm-project/commit/019e7b7f6ed259296d04d9bc1550ea2898f48ec7.diff

LOG: [PartiallyInlineLibCalls] Don't partially inline a musttail libcall.

Partially inlining a libcall that has the musttail attribute
leads to broken LLVM IR, triggering an assertion in the IR verifier.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D123116

Added: 
    llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll

Modified: 
    llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index e0d0301c1ef62..ae102277b9209 100644
--- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
+++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
@@ -125,6 +125,9 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
       if (Call->isNoBuiltin() || Call->isStrictFP())
         continue;
 
+      if (Call->isMustTailCall())
+        continue;
+
       // Skip if function either has local linkage or is not a known library
       // function.
       LibFunc LF;

diff  --git a/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll
new file mode 100644
index 0000000000000..6f4dd91b31ea8
--- /dev/null
+++ b/llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; 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 double @foo(double %x) {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    [[R:%.*]] = musttail call double @sqrt(double [[X:%.*]])
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = musttail call double @sqrt(double %x)
+  ret double %r
+}
+
+declare double @sqrt(double)


        


More information about the llvm-commits mailing list