aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Abrath <bert.abrath@UGent.be>2022-04-05 22:20:52 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2022-04-05 22:30:50 +0300
commit019e7b7f6ed259296d04d9bc1550ea2898f48ec7 (patch)
tree4552d13ba9e46e832b2a77f9f159c011f3400214
parente7f0552682ba644a37beb7699066c08ad83afc97 (diff)
downloadllvm-019e7b7f6ed259296d04d9bc1550ea2898f48ec7.zip
llvm-019e7b7f6ed259296d04d9bc1550ea2898f48ec7.tar.gz
llvm-019e7b7f6ed259296d04d9bc1550ea2898f48ec7.tar.bz2
[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
-rw-r--r--llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp3
-rw-r--r--llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll14
2 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
index e0d0301..ae10227 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 0000000..6f4dd91
--- /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)