[PartiallyInlineLibCalls] Don't partially inline a musttail libcall.
authorBert Abrath <bert.abrath@UGent.be>
Tue, 5 Apr 2022 19:20:52 +0000 (22:20 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 5 Apr 2022 19:30:50 +0000 (22:30 +0300)
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

llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll [new file with mode: 0644]

index e0d0301..ae10227 100644 (file)
@@ -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 (file)
index 0000000..6f4dd91
--- /dev/null
@@ -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)