[clang] [llvm] [Mips] Only limit tail calls to local functions for N32/N64 PIC (PR #247556)

Brad Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 2 14:57:24 PST 2026


https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/247556

>From 173011fe8f7b5d22bdf401f67ffed68f192518bd Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sat, 14 Nov 2026 20:49:33 -0500
Subject: [PATCH] [Mips] Only limit tail calls to local functions for N32/N64
 PIC

A call to a preemptible function in PIC code can go through a lazy
binding stub, which needs $gp to point to the caller's GOT. N32 and N64
make $gp callee-saved, so the epilogue of a tail call restores the
caller's caller's $gp before the jump and the stub uses the wrong GOT.
This is why tail calls were limited to functions that bind locally.

O32 has $gp call-clobbered, so $gp still points to the caller's GOT
when the stub runs, and non-PIC code does not use $gp for calls. Only
apply the limit to N32/N64 PIC code, in both the backend and the clang
musttail check. GCC does the same (TARGET_CALL_SAVED_GP in
mips_function_ok_for_sibcall). Reword the clang error to say when the
limit applies.

Fixes #241732

Assisted-by: Claude Opus 5.5
---
 .../clang/Basic/DiagnosticCommonKinds.td      |   3 +-
 clang/lib/CodeGen/CGCall.cpp                  |   9 +-
 .../Mips/musttail-forward-declaration.c       |   1 +
 clang/test/CodeGen/Mips/musttail-pic.c        |   9 +-
 clang/test/CodeGen/Mips/musttail-visibility.c |   1 +
 clang/test/CodeGen/Mips/musttail-weak.c       |  10 +-
 clang/test/CodeGen/Mips/musttail.c            |  14 +-
 llvm/lib/Target/Mips/MipsISelLowering.cpp     |  14 +-
 llvm/test/CodeGen/Mips/i64arg.ll              |  10 +-
 llvm/test/CodeGen/Mips/lazy-binding.ll        |   2 +-
 llvm/test/CodeGen/Mips/musttail-pic.ll        | 125 ++++++++++++++++
 .../test/CodeGen/Mips/musttail-preemptible.ll |  47 ++++++
 llvm/test/CodeGen/Mips/tailcall/tailcall.ll   | 135 +++++++++---------
 13 files changed, 294 insertions(+), 86 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/musttail-pic.ll
 create mode 100644 llvm/test/CodeGen/Mips/musttail-preemptible.ll

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 84224cd4a342c0..2f8fa2f9df8ac3 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -382,7 +382,8 @@ def err_ppc_impossible_musttail: Error<
 def err_mips_impossible_musttail: Error<
   "'musttail' attribute for this call is impossible because %select{"
   "the MIPS16 ABI does not support tail calls|"
-  "calls outside the current linkage unit cannot be tail called on MIPS}0"
+  "calls to preemptible functions cannot be tail called in MIPS N32/N64 PIC "
+  "code}0"
   >;
 def err_aix_musttail_unsupported: Error<
   "'musttail' attribute is not supported on AIX">;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 16aab24f8bc17f..7614faecb540f5 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -6681,8 +6681,13 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       if (IsMIPS) {
         if (HasMips16)
           CGM.getDiags().Report(Loc, diag::err_mips_impossible_musttail) << 0;
-        else if (const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
-          CGM.addUndefinedGlobalForTailCall({FD, Loc});
+        else if (const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
+          // The N32 and N64 ABIs make $gp callee-saved, so PIC code can only
+          // tail call functions that bind locally. O32 has no such limit.
+          if (CGM.getCodeGenOpts().RelocationModel == llvm::Reloc::PIC_ &&
+              getTarget().getABI() != "o32")
+            CGM.addUndefinedGlobalForTailCall({FD, Loc});
+        }
       }
       Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
     }
diff --git a/clang/test/CodeGen/Mips/musttail-forward-declaration.c b/clang/test/CodeGen/Mips/musttail-forward-declaration.c
index b25baa76f451fe..51cc01d2a03826 100644
--- a/clang/test/CodeGen/Mips/musttail-forward-declaration.c
+++ b/clang/test/CodeGen/Mips/musttail-forward-declaration.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -o /dev/null -emit-llvm -verify
+// RUN: %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 -o /dev/null -emit-llvm -verify
 
 // Test that a forward declaration that is later defined in the same TU
 // is allowed for musttail calls.
diff --git a/clang/test/CodeGen/Mips/musttail-pic.c b/clang/test/CodeGen/Mips/musttail-pic.c
index bcad84d63f1934..68eca7ce0e41f4 100644
--- a/clang/test/CodeGen/Mips/musttail-pic.c
+++ b/clang/test/CodeGen/Mips/musttail-pic.c
@@ -1,14 +1,19 @@
+// RUN: %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 -pic-level 2 \
+// RUN:   -fhalf-no-semantic-interposition -o /dev/null -emit-llvm -verify=n64
 // RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -pic-level 2 \
-// RUN:   -fhalf-no-semantic-interposition -o /dev/null -emit-llvm -verify
+// RUN:   -fhalf-no-semantic-interposition -o /dev/null -emit-llvm -verify=o32
 
 // Test musttail behavior in PIC mode with semantic interposition.
+// N64 can only tail call functions that bind locally. O32 has no such limit.
+
+// o32-no-diagnostics
 
 int external_defined(int i) { return i; }
 static int static_func(int i) { return i; }
 __attribute__((visibility("hidden"))) int hidden_defined(int i) { return i; }
 
 int call_external(int i) {
-  // expected-error at +1 {{'musttail' attribute for this call is impossible because calls outside the current linkage unit cannot be tail called on MIPS}}
+  // n64-error at +1 {{'musttail' attribute for this call is impossible because calls to preemptible functions cannot be tail called in MIPS N32/N64 PIC code}}
   [[clang::musttail]] return external_defined(i);
 }
 
diff --git a/clang/test/CodeGen/Mips/musttail-visibility.c b/clang/test/CodeGen/Mips/musttail-visibility.c
index 351563e991129c..2612f7544ae2f2 100644
--- a/clang/test/CodeGen/Mips/musttail-visibility.c
+++ b/clang/test/CodeGen/Mips/musttail-visibility.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -o /dev/null -emit-llvm -verify
+// RUN: %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 -o /dev/null -emit-llvm -verify
 
 // Test that hidden and protected visibility functions can be tail called
 // because they are guaranteed to be DSO-local.
diff --git a/clang/test/CodeGen/Mips/musttail-weak.c b/clang/test/CodeGen/Mips/musttail-weak.c
index 06c0726d3d1e1f..e29bf9c5da6e7d 100644
--- a/clang/test/CodeGen/Mips/musttail-weak.c
+++ b/clang/test/CodeGen/Mips/musttail-weak.c
@@ -1,13 +1,19 @@
-// RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -o /dev/null -emit-llvm -verify
+// RUN: %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 -o /dev/null \
+// RUN:   -emit-llvm -verify=n64
+// RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -o /dev/null \
+// RUN:   -emit-llvm -verify=o32
 
 // Test musttail with weak functions.
 // Weak functions can be interposed, so they are not considered DSO-local.
+// That only matters for N32/N64 PIC code.
+
+// o32-no-diagnostics
 
 __attribute__((weak)) int weak_func(int i) {
   return i;
 }
 
 int caller(int i) {
-  // expected-error at +1 {{'musttail' attribute for this call is impossible because calls outside the current linkage unit cannot be tail called on MIPS}}
+  // n64-error at +1 {{'musttail' attribute for this call is impossible because calls to preemptible functions cannot be tail called in MIPS N32/N64 PIC code}}
   [[clang::musttail]] return weak_func(i);
 }
diff --git a/clang/test/CodeGen/Mips/musttail.c b/clang/test/CodeGen/Mips/musttail.c
index 38c27e508e9119..53ffd386ee0736 100644
--- a/clang/test/CodeGen/Mips/musttail.c
+++ b/clang/test/CodeGen/Mips/musttail.c
@@ -1,9 +1,17 @@
-// RUN: not %clang_cc1 %s -triple mipsel-unknown-linux-gnu -emit-llvm -o /dev/null 2>&1 \
-// RUN:   | FileCheck %s
+// RUN: %clang_cc1 %s -triple mipsel-unknown-linux-gnu -emit-llvm -o /dev/null
+// RUN: %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 \
+// RUN:   -mrelocation-model static -emit-llvm -o /dev/null
+// RUN: not %clang_cc1 %s -triple mips64el-unknown-linux-gnuabi64 \
+// RUN:   -emit-llvm -o /dev/null 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 %s -triple mips64el-unknown-linux-gnuabin32 \
+// RUN:   -emit-llvm -o /dev/null 2>&1 | FileCheck %s
 // RUN: not %clang_cc1 %s -triple mipsel-unknown-linux-gnu -target-feature +mips16 \
 // RUN:   -emit-llvm -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-MIPS16
 
-// CHECK: error: 'musttail' attribute for this call is impossible because calls outside the current linkage unit cannot be tail called on MIPS
+// O32 and non-PIC code can tail call external functions. N32 and N64 PIC code
+// can not, because $gp is callee-saved there.
+
+// CHECK: error: 'musttail' attribute for this call is impossible because calls to preemptible functions cannot be tail called in MIPS N32/N64 PIC code
 // CHECK-MIPS16: error: 'musttail' attribute for this call is impossible because the MIPS16 ABI does not support tail calls
 
 static int local(int x) { return x; }
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index d2d3a08eae72b0..dd389a7a260c3e 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -3679,13 +3679,17 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
   setTypeIdForCallsiteInfo(CB, MF, CSInfo);
 
   // Check if it's really possible to do a tail call.
-  // For non-musttail calls, restrict to functions that won't require $gp
-  // restoration. In PIC mode, calling external functions via tail call can
-  // cause issues with $gp register handling (see D24763).
+  // In PIC code, a call to a preemptible function may go through a lazy
+  // binding stub, which needs $gp to point to the caller's GOT. The N32 and
+  // N64 ABIs make $gp callee-saved, so the epilogue restores $gp before the
+  // tail call and the stub would see the wrong GOT. Only allow tail calls to
+  // functions that bind locally in that case. O32 has $gp call-clobbered, so
+  // $gp still points to the caller's GOT when the stub runs.
   bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall();
   bool CalleeIsLocal = true;
-  if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
-    const GlobalValue *GV = G->getGlobal();
+  GlobalAddressSDNode *CalleeG = dyn_cast<GlobalAddressSDNode>(Callee);
+  if (CalleeG && IsPIC && !ABI.IsO32()) {
+    const GlobalValue *GV = CalleeG->getGlobal();
     bool HasLocalLinkage = GV->hasLocalLinkage() || GV->hasPrivateLinkage();
     bool HasHiddenVisibility =
         GV->hasHiddenVisibility() || GV->hasProtectedVisibility();
diff --git a/llvm/test/CodeGen/Mips/i64arg.ll b/llvm/test/CodeGen/Mips/i64arg.ll
index 2af16f7d23f3c1..e518721bc61968 100644
--- a/llvm/test/CodeGen/Mips/i64arg.ll
+++ b/llvm/test/CodeGen/Mips/i64arg.ll
@@ -2,8 +2,8 @@
 
 define void @f1(i64 %ll1, float %f, i64 %ll, i32 %i, float %f2) nounwind {
 entry:
-; CHECK-DAG: lw $[[R2:[0-9]+]], 80($sp)
-; CHECK-DAG: lw $[[R3:[0-9]+]], 84($sp)
+; CHECK-DAG: lw $[[R2:[0-9]+]], 64($sp)
+; CHECK-DAG: lw $[[R3:[0-9]+]], 68($sp)
 ; CHECK-DAG: move $[[R1:[0-9]+]], $5
 ; CHECK-DAG: move $[[R0:[0-9]+]], $4
 ; CHECK-DAG: ori $6, ${{[0-9]+}}, 3855
@@ -18,11 +18,11 @@ entry:
   tail call void @ff2(i64 %ll, double 3.000000e+00) nounwind
   %sub = add nsw i32 %i, -1
 ; CHECK-DAG: lw $25, %call16(ff3)
-; CHECK-DAG: sw $[[R1]], 28($sp)
-; CHECK-DAG: sw $[[R0]], 24($sp)
+; CHECK-DAG: sw $[[R1]], 76($sp)
+; CHECK-DAG: sw $[[R0]], 72($sp)
 ; CHECK-DAG: move $6, $[[R2]]
 ; CHECK-DAG: move $7, $[[R3]]
-; CHECK:     jalr $25
+; CHECK:     jr $25
   tail call void @ff3(i32 %i, i64 %ll, i32 %sub, i64 %ll1) nounwind
   ret void
 }
diff --git a/llvm/test/CodeGen/Mips/lazy-binding.ll b/llvm/test/CodeGen/Mips/lazy-binding.ll
index e9860acb91bb4e..ab0f58094062cb 100644
--- a/llvm/test/CodeGen/Mips/lazy-binding.ll
+++ b/llvm/test/CodeGen/Mips/lazy-binding.ll
@@ -30,7 +30,7 @@ declare void @foo2()
 ; CHECK: lw $25, %call16(foo2)(${{[0-9]+}})
 ; CHECK: jalr $25
 ; CHECK: lw $25, %call16(foo2)(${{[0-9]+}})
-; CHECK: jalr $25
+; CHECK: jr $25
 
 define void @foo1() {
 entry:
diff --git a/llvm/test/CodeGen/Mips/musttail-pic.ll b/llvm/test/CodeGen/Mips/musttail-pic.ll
new file mode 100644
index 00000000000000..e973dbe45ec129
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/musttail-pic.ll
@@ -0,0 +1,125 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=mipsel-unknown-linux-gnu -relocation-model=pic \
+; RUN:   -mips-tail-calls=1 < %s | FileCheck %s --check-prefix=O32-PIC
+; RUN: llc -mtriple=mipsel-unknown-linux-gnu -relocation-model=static \
+; RUN:   -mips-tail-calls=1 < %s | FileCheck %s --check-prefix=O32-STATIC
+; RUN: llc -mtriple=mips64el-unknown-linux-gnuabi64 -relocation-model=static \
+; RUN:   -mips-tail-calls=1 < %s | FileCheck %s --check-prefix=N64-STATIC
+
+; Test musttail calls to functions that may be preempted. O32 has $gp
+; call-clobbered, so these can be tail called in PIC code. Non-PIC code does
+; not use $gp for calls. N32/N64 PIC is tested in
+; musttail-preemptible.ll.
+
+declare i32 @external(i32)
+
+define i32 @test_external(i32 %x) {
+; O32-PIC-LABEL: test_external:
+; O32-PIC:       # %bb.0:
+; O32-PIC-NEXT:    lui $2, %hi(_gp_disp)
+; O32-PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
+; O32-PIC-NEXT:    addu $gp, $2, $25
+; O32-PIC-NEXT:    lw $25, %call16(external)($gp)
+; O32-PIC-NEXT:    .reloc $tmp0, R_MIPS_JALR, external
+; O32-PIC-NEXT:  $tmp0:
+; O32-PIC-NEXT:    jr $25
+; O32-PIC-NEXT:    nop
+;
+; O32-STATIC-LABEL: test_external:
+; O32-STATIC:       # %bb.0:
+; O32-STATIC-NEXT:    j external
+; O32-STATIC-NEXT:    nop
+;
+; N64-STATIC-LABEL: test_external:
+; N64-STATIC:       # %bb.0:
+; N64-STATIC-NEXT:    j external
+; N64-STATIC-NEXT:    nop
+  %ret = musttail call i32 @external(i32 %x)
+  ret i32 %ret
+}
+
+define i32 @defined(i32 %x) {
+; O32-PIC-LABEL: defined:
+; O32-PIC:       # %bb.0:
+; O32-PIC-NEXT:    jr $ra
+; O32-PIC-NEXT:    move $2, $4
+;
+; O32-STATIC-LABEL: defined:
+; O32-STATIC:       # %bb.0:
+; O32-STATIC-NEXT:    jr $ra
+; O32-STATIC-NEXT:    move $2, $4
+;
+; N64-STATIC-LABEL: defined:
+; N64-STATIC:       # %bb.0:
+; N64-STATIC-NEXT:    jr $ra
+; N64-STATIC-NEXT:    sll $2, $4, 0
+  ret i32 %x
+}
+
+define i32 @test_defined(i32 %x) {
+; O32-PIC-LABEL: test_defined:
+; O32-PIC:       # %bb.0:
+; O32-PIC-NEXT:    lui $2, %hi(_gp_disp)
+; O32-PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
+; O32-PIC-NEXT:    addu $gp, $2, $25
+; O32-PIC-NEXT:    lw $25, %call16(defined)($gp)
+; O32-PIC-NEXT:    .reloc $tmp1, R_MIPS_JALR, defined
+; O32-PIC-NEXT:  $tmp1:
+; O32-PIC-NEXT:    jr $25
+; O32-PIC-NEXT:    nop
+;
+; O32-STATIC-LABEL: test_defined:
+; O32-STATIC:       # %bb.0:
+; O32-STATIC-NEXT:    j defined
+; O32-STATIC-NEXT:    nop
+;
+; N64-STATIC-LABEL: test_defined:
+; N64-STATIC:       # %bb.0:
+; N64-STATIC-NEXT:    j defined
+; N64-STATIC-NEXT:    nop
+  %ret = musttail call i32 @defined(i32 %x)
+  ret i32 %ret
+}
+
+define weak i32 @weak(i32 %x) {
+; O32-PIC-LABEL: weak:
+; O32-PIC:       # %bb.0:
+; O32-PIC-NEXT:    jr $ra
+; O32-PIC-NEXT:    move $2, $4
+;
+; O32-STATIC-LABEL: weak:
+; O32-STATIC:       # %bb.0:
+; O32-STATIC-NEXT:    jr $ra
+; O32-STATIC-NEXT:    move $2, $4
+;
+; N64-STATIC-LABEL: weak:
+; N64-STATIC:       # %bb.0:
+; N64-STATIC-NEXT:    jr $ra
+; N64-STATIC-NEXT:    sll $2, $4, 0
+  ret i32 %x
+}
+
+define i32 @test_weak(i32 %x) {
+; O32-PIC-LABEL: test_weak:
+; O32-PIC:       # %bb.0:
+; O32-PIC-NEXT:    lui $2, %hi(_gp_disp)
+; O32-PIC-NEXT:    addiu $2, $2, %lo(_gp_disp)
+; O32-PIC-NEXT:    addu $gp, $2, $25
+; O32-PIC-NEXT:    lw $25, %call16(weak)($gp)
+; O32-PIC-NEXT:    .reloc $tmp2, R_MIPS_JALR, weak
+; O32-PIC-NEXT:  $tmp2:
+; O32-PIC-NEXT:    jr $25
+; O32-PIC-NEXT:    nop
+;
+; O32-STATIC-LABEL: test_weak:
+; O32-STATIC:       # %bb.0:
+; O32-STATIC-NEXT:    j weak
+; O32-STATIC-NEXT:    nop
+;
+; N64-STATIC-LABEL: test_weak:
+; N64-STATIC:       # %bb.0:
+; N64-STATIC-NEXT:    j weak
+; N64-STATIC-NEXT:    nop
+  %ret = musttail call i32 @weak(i32 %x)
+  ret i32 %ret
+}
diff --git a/llvm/test/CodeGen/Mips/musttail-preemptible.ll b/llvm/test/CodeGen/Mips/musttail-preemptible.ll
new file mode 100644
index 00000000000000..2387bceacf5e74
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/musttail-preemptible.ll
@@ -0,0 +1,47 @@
+; RUN: split-file %s %t
+; RUN: llc -mtriple=mips64el-unknown-linux-gnuabi64 -relocation-model=pic \
+; RUN:   -mips-tail-calls=1 < %t/local.ll | FileCheck %s --check-prefix=LOCAL
+; RUN: llc -mtriple=mips64el-unknown-linux-gnuabin32 -relocation-model=pic \
+; RUN:   -mips-tail-calls=1 < %t/local.ll | FileCheck %s --check-prefix=LOCAL
+; RUN: not --crash llc -mtriple=mips64el-unknown-linux-gnuabi64 \
+; RUN:   -relocation-model=pic -mips-tail-calls=1 < %t/external.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=EXTERNAL
+; RUN: not --crash llc -mtriple=mips64el-unknown-linux-gnuabin32 \
+; RUN:   -relocation-model=pic -mips-tail-calls=1 < %t/external.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=EXTERNAL
+
+; N32 and N64 have $gp callee-saved, so PIC code can only tail call functions
+; that bind locally. A lazy binding stub would see the wrong $gp.
+
+; EXTERNAL: LLVM ERROR: failed to perform tail call elimination on a call site marked musttail
+
+;--- local.ll
+declare hidden i32 @hidden(i32)
+
+define i32 @test_hidden(i32 %x) {
+; LOCAL-LABEL: test_hidden:
+; LOCAL-NOT:   jalr
+; LOCAL:       jr $25
+  %ret = musttail call i32 @hidden(i32 %x)
+  ret i32 %ret
+}
+
+define internal i32 @internal(i32 %x) {
+  ret i32 %x
+}
+
+define i32 @test_internal(i32 %x) {
+; LOCAL-LABEL: test_internal:
+; LOCAL-NOT:   jalr
+; LOCAL:       jr $25
+  %ret = musttail call i32 @internal(i32 %x)
+  ret i32 %ret
+}
+
+;--- external.ll
+declare i32 @external(i32)
+
+define i32 @test_external(i32 %x) {
+  %ret = musttail call i32 @external(i32 %x)
+  ret i32 %ret
+}
diff --git a/llvm/test/CodeGen/Mips/tailcall/tailcall.ll b/llvm/test/CodeGen/Mips/tailcall/tailcall.ll
index c2ab02243cb82e..1c5161d75fb796 100644
--- a/llvm/test/CodeGen/Mips/tailcall/tailcall.ll
+++ b/llvm/test/CodeGen/Mips/tailcall/tailcall.ll
@@ -22,7 +22,7 @@
 ; RUN: llc -mtriple=mips64el -relocation-model=pic -mcpu=mips64r2 -verify-machineinstrs \
 ; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=PIC64
 ; RUN: llc -mtriple=mips64el -relocation-model=pic -mcpu=mips64r6 -verify-machineinstrs \
-; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefix=STATIC64
+; RUN:     -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,PIC64R6
 
 ; RUN: llc -mtriple=mipsel -relocation-model=pic -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs \
 ; RUN:      -mips-tail-calls=1 < %s | FileCheck %s -check-prefixes=ALL,PIC32MMR6
@@ -43,14 +43,15 @@
 define i32 @caller1(i32 %a0) nounwind {
 entry:
 ; ALL-LABEL: caller1:
-; PIC32: jalr $25
-; PIC32MM: jalrs16 $25
-; PIC32MMR6: jalr $25
-; PIC32R6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; N64: jalr $25
-; N64R6: jalr $25
+; PIC32: jr $25
+; PIC32R6: jr $25
+; PIC32MM: jr $25
+; PIC32MMR6: jrc $25
+; STATIC32: j callee1
+; STATIC32MMR6: bc callee1
+; PIC64: jalr $25
+; PIC64R6: jalr $25
+; STATIC64: j callee1
 ; PIC16: jalrc
 
   %call = tail call i32 @callee1(i32 1, i32 1, i32 1, i32 %a0) nounwind
@@ -61,15 +62,16 @@ declare i32 @callee1(i32, i32, i32, i32)
 
 define i32 @caller2(i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind {
 entry:
-; ALL-LABEL: caller2
+; ALL-LABEL: caller2:
 ; PIC32: jalr $25
+; PIC32R6: jalr $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; PIC32R6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; N64: jalr $25
-; N64R6: jalr $25
+; STATIC32: jal callee2
+; STATIC32MMR6: balc callee2
+; PIC64: jalr $25
+; PIC64R6: jalr $25
+; STATIC64: j callee2
 ; PIC16: jalrc
 
   %call = tail call i32 @callee2(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3) nounwind
@@ -85,10 +87,11 @@ entry:
 ; PIC32R6: jalr $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; N64: jalr $25
-; N64R6: jalr $25
+; STATIC32: jal callee3
+; STATIC32MMR6: balc callee3
+; PIC64: jalr $25
+; PIC64R6: jalr $25
+; STATIC64: j callee3
 ; PIC16: jalrc
 
   %call = tail call i32 @callee3(i32 1, i32 1, i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) nounwind
@@ -104,11 +107,11 @@ entry:
 ; PIC32R6: jalr $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; STATIC32: jal
-; SATATIC32MMR6: jal
+; STATIC32: jal callee4
+; STATIC32MMR6: balc callee4
 ; PIC64: jalr $25
-; STATIC64: jal
-; N64R6: jalr $25
+; PIC64R6: jalr $25
+; STATIC64: jal callee4
 ; PIC16: jalrc
 
   %call = tail call i32 @callee4(i32 1, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
@@ -122,12 +125,13 @@ entry:
 ; ALL-LABEL: caller5:
 ; PIC32: jr $25
 ; PIC32R6: jr $25
-; PIC32MM: jr
-; PIC32MMR6: jr
-; STATIC32: j
-; STATIC32MMR6: bc
+; PIC32MM: jr $25
+; PIC32MMR6: jrc $25
+; STATIC32: j callee5
+; STATIC32MMR6: bc callee5
 ; PIC64: jr $25
-; STATIC64: j
+; PIC64R6: jr $25
+; STATIC64: j callee5
 ; PIC16: jalrc
 
   %0 = load i32, ptr @g0, align 4
@@ -166,12 +170,12 @@ entry:
 ; PIC32: jr $25
 ; PIC32R6: jrc $25
 ; PIC32MM: jr $25
-; PIC32MMR6: jrc
-; STATIC32: j
-; STATIC32MMR6: bc
+; PIC32MMR6: jrc $25
+; STATIC32: j caller8_1
+; STATIC32MMR6: bc caller8_1
 ; PIC64: jr $25
 ; PIC64R6: jrc $25
-; STATIC64: j
+; STATIC64: j caller8_1
 ; PIC16: jalrc
 
   %call = tail call fastcc i32 @caller8_1()
@@ -186,9 +190,10 @@ entry:
 ; PIC32MM: jalrs16 $25
 ; PIC32MMR6: jalr $25
 ; STATIC32: jal
-; STATIC32MMR6: balc
+; STATIC32MMR6: balc callee8
 ; PIC64: jalr $25
-; STATIC64: jal
+; PIC64R6: jalr $25
+; STATIC64: j callee8
 ; PIC16: jalrc
 
   %call = tail call i32 (i32, ...) @callee8(i32 2, i32 1) nounwind
@@ -207,12 +212,12 @@ entry:
 ; PIC32: jr $25
 ; PIC32R6: jrc $25
 ; PIC32MM: jr $25
-; PIC32MMR6: jrc
-; STATIC32: j
-; STATIC32MMR6: bc
+; PIC32MMR6: jrc $25
+; STATIC32: j caller9_1
+; STATIC32MMR6: bc caller9_1
 ; PIC64: jr $25
-; STATIC64: j
 ; PIC64R6: jrc $25
+; STATIC64: j caller9_1
 ; PIC16: jalrc
   %call = tail call fastcc i32 @caller9_1()
   ret i32 %call
@@ -225,11 +230,11 @@ entry:
 ; PIC32R6: jalrc $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; STATIC64: jal
+; STATIC32: jal callee9
+; STATIC32MMR6: balc callee9
 ; PIC64: jalr $25
 ; PIC64R6: jalrc $25
+; STATIC64: jal callee9
 ; PIC16: jalrc
 
   %call = tail call i32 @callee9(ptr byval(%struct.S) @gs1) nounwind
@@ -241,15 +246,15 @@ declare i32 @callee10(i32, i32, i32, i32, i32, i32, i32, i32, i32)
 define i32 @caller10(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7, i32 %a8) nounwind {
 entry:
 ; ALL-LABEL: caller10:
-; PIC32: jalr $25
-; PIC32R6: jalr $25
-; PIC32MM: jalr $25
-; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; STATIC64: jal
+; PIC32: jr $25
+; PIC32R6: jr $25
+; PIC32MM: jr $25
+; PIC32MMR6: jrc $25
+; STATIC32: j callee10
+; STATIC32MMR6: bc callee10
 ; PIC64: jalr $25
 ; PIC64R6: jalr $25
+; STATIC64: j callee10
 ; PIC16: jalrc
 
   %call = tail call i32 @callee10(i32 %a8, i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7) nounwind
@@ -265,11 +270,11 @@ entry:
 ; PIC32R6: jalrc $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; STATIC64: jal
+; STATIC32: jal callee11
+; STATIC32MMR6: balc callee11
 ; PIC64: jalr $25
 ; PIC64R6: jalrc $25
+; STATIC64: jal callee11
 ; PIC16: jalrc
 
   %call = tail call i32 @callee11(ptr byval(%struct.S) @gs1) nounwind
@@ -287,11 +292,11 @@ entry:
 ; PIC32R6: jalrc $25
 ; PIC32MM: jalr $25
 ; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; STATIC64: jal
+; STATIC32: jal callee12
+; STATIC32MMR6: balc callee12
 ; PIC64: jalr $25
 ; PIC64R6: jalrc $25
+; STATIC64: jal callee12
 ; PIC16: jalrc
 
   tail call void @llvm.memcpy.p0.p0.i32(ptr align 4 @gs1, ptr align 4 %a0, i32 8, i1 false)
@@ -304,15 +309,15 @@ declare i32 @callee13(i32, ...)
 define i32 @caller13() nounwind {
 entry:
 ; ALL-LABEL: caller13:
-; PIC32: jalr $25
-; PIC32R6: jalr $25
-; PIC32MM: jalrs16 $25
-; PIC32MMR6: jalr $25
-; STATIC32: jal
-; STATIC32MMR6: balc
-; STATIC64: jal
-; PIC64R6: jalr $25
+; PIC32: jr $25
+; PIC32R6: jr $25
+; PIC32MM: jr $25
+; PIC32MMR6: jrc $25
+; STATIC32: j callee13
+; STATIC32MMR6: bc callee13
 ; PIC64: jalr $25
+; PIC64R6: jalr $25
+; STATIC64: j callee13
 ; PIC16: jalrc
 
   %call = tail call i32 (i32, ...) @callee13(i32 1, i32 2) nounwind
@@ -322,11 +327,11 @@ entry:
 ; Check that there is a chain edge between the load and store nodes.
 ;
 ; ALL-LABEL: caller14:
-; PIC32: lw ${{[0-9]+}}, 48($sp)
+; PIC32: lw ${{[0-9]+}}, 16($sp)
 ; PIC32: sw $4, 16($sp)
 
-; PIC32MM: lw ${{[0-9]+}}, 48($sp)
-; PIC32MM: sw16 $4, 16(${{[0-9]+}})
+; PIC32MM: lw ${{[0-9]+}}, 16($sp)
+; PIC32MM: sw $4, 16($sp)
 
 define void @caller14(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 entry:



More information about the cfe-commits mailing list