-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[HotColdSplit] Don't outline musttail calls. #133177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HotColdSplit] Don't outline musttail calls. #133177
Conversation
musttail calls have several restrictions, generally enforcing matching calling conventions between the caller parent and musttail callee. We can't usually honor them, because the extracted function has a different signature altogether, taking inputs/outputs and returning a control-flow identifier rather than the actual return value. Don't consider musttail calls as valid for extraction.
@llvm/pr-subscribers-llvm-transforms Author: Ahmed Bougacha (ahmedbougacha) Changesmusttail calls have several restrictions, generally enforcing matching calling conventions between the caller parent and musttail callee. We can't usually honor them, because the extracted function has a different signature altogether, taking inputs/outputs and returning a control-flow identifier rather than the actual return value. Don't consider musttail calls as valid for extraction. Full diff: https://github.com/llvm/llvm-project/pull/133177.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index 7277603b3ec2b..216db3a4570f7 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -170,6 +170,14 @@ static bool isBlockValidForExtraction(const BasicBlock &BB,
}
if (const CallInst *CI = dyn_cast<CallInst>(I)) {
+ // musttail calls have several restrictions, generally enforcing matching
+ // calling conventions between the caller parent and musttail callee.
+ // We can't usually honor them, because the extracted function has a
+ // different signature altogether, taking inputs/outputs and returning
+ // a control-flow identifier rather than the actual return value.
+ if (CI->isMustTailCall())
+ return false;
+
if (const Function *F = CI->getCalledFunction()) {
auto IID = F->getIntrinsicID();
if (IID == Intrinsic::vastart) {
diff --git a/llvm/test/Transforms/HotColdSplit/musttail.ll b/llvm/test/Transforms/HotColdSplit/musttail.ll
new file mode 100644
index 0000000000000..b7108bd6e6cd9
--- /dev/null
+++ b/llvm/test/Transforms/HotColdSplit/musttail.ll
@@ -0,0 +1,53 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s
+
+; musttail calls can't be outlined, because they have several restrictions
+; enforcing matching calling conventions between the parent and callee.
+
+define void @test_musttail(i1 %b) {
+; CHECK-LABEL: define void @test_musttail(
+; CHECK-SAME: i1 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[B]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
+; CHECK: [[IF_THEN]]:
+; CHECK-NEXT: ret void
+; CHECK: [[IF_ELSE]]:
+; CHECK-NEXT: musttail call void @target(i1 [[B]])
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %b, label %if.then, label %if.else
+
+if.then:
+ ret void
+
+if.else:
+ musttail call void @target(i1 %b)
+ ret void
+}
+
+define void @test_tail(i1 %b) {
+; CHECK-LABEL: define void @test_tail(
+; CHECK-SAME: i1 [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: br i1 [[B]], label %[[IF_THEN:.*]], label %[[CODEREPL:.*]]
+; CHECK: [[IF_THEN]]:
+; CHECK-NEXT: ret void
+; CHECK: [[CODEREPL]]:
+; CHECK-NEXT: call void @test_tail.cold.1(i1 [[B]]) #[[ATTR2:[0-9]+]]
+; CHECK-NEXT: br label %[[IF_ELSE_RET:.*]]
+; CHECK: [[IF_ELSE_RET]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br i1 %b, label %if.then, label %if.else
+
+if.then:
+ ret void
+
+if.else:
+ tail call void @target(i1 %b)
+ ret void
+}
+
+declare void @target() cold
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/13685 Here is the relevant piece of the build log for the reference
|
musttail calls have several restrictions, generally enforcing matching calling conventions between the caller parent and musttail callee. We can't usually honor them, because the extracted function has a different signature altogether, taking inputs/outputs and returning a control-flow identifier rather than the actual return value.
Don't consider musttail calls as valid for extraction.