-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MIPS][ISel] Fix musttail #161860
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
base: main
Are you sure you want to change the base?
[MIPS][ISel] Fix musttail #161860
Conversation
Properly handle clang::musttail attribute on MIPS backend.
@llvm/pr-subscribers-backend-mips Author: Djordje Todorovic (djtodoro) ChangesProperly handle clang::musttail attribute on MIPS backend. It fixes: #161193 Full diff: https://github.com/llvm/llvm-project/pull/161860.diff 2 Files Affected:
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 881ba8e2f9eff..d79db127f01a2 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -3407,7 +3407,8 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// Check if it's really possible to do a tail call. Restrict it to functions
// that are part of this compilation unit.
bool InternalLinkage = false;
- if (IsTailCall) {
+ bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
+ if (IsTailCall && !IsMustTail) {
IsTailCall = isEligibleForTailCallOptimization(
CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>());
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
@@ -3416,9 +3417,9 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
G->getGlobal()->hasPrivateLinkage() ||
G->getGlobal()->hasHiddenVisibility() ||
G->getGlobal()->hasProtectedVisibility());
- }
+ }
}
- if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall())
+ if (!IsTailCall && IsMustTail)
report_fatal_error("failed to perform tail call elimination on a call "
"site marked musttail");
diff --git a/llvm/test/CodeGen/Mips/musttail.ll b/llvm/test/CodeGen/Mips/musttail.ll
new file mode 100644
index 0000000000000..d5f457f6eb665
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/musttail.ll
@@ -0,0 +1,38 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=mips-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS32
+; RUN: llc -mtriple=mips64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS64
+
+; Test musttail support for MIPS
+
+declare void @external_func()
+
+; Test basic musttail with external function
+define void @test_musttail_external() {
+; MIPS32-LABEL: test_musttail_external:
+; MIPS32: # %bb.0:
+; MIPS32-NEXT: j external_func
+; MIPS32-NEXT: nop
+;
+; MIPS64-LABEL: test_musttail_external:
+; MIPS64: # %bb.0:
+; MIPS64-NEXT: j external_func
+; MIPS64-NEXT: nop
+ musttail call void @external_func()
+ ret void
+}
+
+declare i32 @callee_args(i32 %a, i32 %b, i32 %c)
+
+define i32 @test_musttail_args(i32 %x, i32 %y, i32 %z) {
+; MIPS32-LABEL: test_musttail_args:
+; MIPS32: # %bb.0:
+; MIPS32-NEXT: j callee_args
+; MIPS32-NEXT: nop
+;
+; MIPS64-LABEL: test_musttail_args:
+; MIPS64: # %bb.0:
+; MIPS64-NEXT: j callee_args
+; MIPS64-NEXT: nop
+ %ret = musttail call i32 @callee_args(i32 %x, i32 %y, i32 %z)
+ ret i32 %ret
+}
|
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
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.
Uh don't we still need to check it's eligible?
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.
Well, that thing confuses me in the case of musttail
. On ARM, we do check it. Lets do it for MIPS as well.
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.
@jrtc27 yep, it does make sense to still check it. I incorporated in the new commit (basically - do not check for the optional mips flag for enabling tail call optimizations in case of musttial
, and I also enabled tail call opts for dso_local
functions (1dcb9110612ab
) ). Thanks for the review!
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.
.
I checked the issues listed above, all cases from those still pass with the new patch. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
Please squash changes into initial commit |
Per "Contributing to LLVM" Policy, we do not do force-push (and squash), we rather use incremental changes to address comments during review process. And, once the pull request is approved, we select the “Squash and merge” button. |
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.
my checks pass with this series as well.
right, squashing is what I meant. |
I will wait for @jrtc27 to have another look. :) |
Properly handle clang::musttail attribute on MIPS backend.
It fixes: #161193