Skip to content

Commit ac9497e

Browse files
committed
[MIPS][ISel] Fix musttail
Properly handle clang::musttail attribute on MIPS backend.
1 parent 1acfa18 commit ac9497e

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,8 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
34073407
// Check if it's really possible to do a tail call. Restrict it to functions
34083408
// that are part of this compilation unit.
34093409
bool InternalLinkage = false;
3410-
if (IsTailCall) {
3410+
bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
3411+
if (IsTailCall && !IsMustTail) {
34113412
IsTailCall = isEligibleForTailCallOptimization(
34123413
CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>());
34133414
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
@@ -3416,9 +3417,9 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
34163417
G->getGlobal()->hasPrivateLinkage() ||
34173418
G->getGlobal()->hasHiddenVisibility() ||
34183419
G->getGlobal()->hasProtectedVisibility());
3419-
}
3420+
}
34203421
}
3421-
if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall())
3422+
if (!IsTailCall && IsMustTail)
34223423
report_fatal_error("failed to perform tail call elimination on a call "
34233424
"site marked musttail");
34243425

llvm/test/CodeGen/Mips/musttail.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=mips-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS32
3+
; RUN: llc -mtriple=mips64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS64
4+
5+
; Test musttail support for MIPS
6+
7+
declare void @external_func()
8+
9+
; Test basic musttail with external function
10+
define void @test_musttail_external() {
11+
; MIPS32-LABEL: test_musttail_external:
12+
; MIPS32: # %bb.0:
13+
; MIPS32-NEXT: j external_func
14+
; MIPS32-NEXT: nop
15+
;
16+
; MIPS64-LABEL: test_musttail_external:
17+
; MIPS64: # %bb.0:
18+
; MIPS64-NEXT: j external_func
19+
; MIPS64-NEXT: nop
20+
musttail call void @external_func()
21+
ret void
22+
}
23+
24+
declare i32 @callee_args(i32 %a, i32 %b, i32 %c)
25+
26+
define i32 @test_musttail_args(i32 %x, i32 %y, i32 %z) {
27+
; MIPS32-LABEL: test_musttail_args:
28+
; MIPS32: # %bb.0:
29+
; MIPS32-NEXT: j callee_args
30+
; MIPS32-NEXT: nop
31+
;
32+
; MIPS64-LABEL: test_musttail_args:
33+
; MIPS64: # %bb.0:
34+
; MIPS64-NEXT: j callee_args
35+
; MIPS64-NEXT: nop
36+
%ret = musttail call i32 @callee_args(i32 %x, i32 %y, i32 %z)
37+
ret i32 %ret
38+
}

0 commit comments

Comments
 (0)