[llvm-branch-commits] [llvm] 52e90e1 - [Mips] Lower calls to private functions the same way as internal functions (#229975)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Oct 18 23:24:02 PDT 2026
Author: Alex Rønne Petersen
Date: 2026-10-19T08:23:54+02:00
New Revision: 52e90e1917a4bbc450d9ac56030bab755246a269
URL: https://github.com/llvm/llvm-project/commit/52e90e1917a4bbc450d9ac56030bab755246a269
DIFF: https://github.com/llvm/llvm-project/commit/52e90e1917a4bbc450d9ac56030bab755246a269.diff
LOG: [Mips] Lower calls to private functions the same way as internal functions (#229975)
As with 85b4fbfecb65cd1f5a06e707e7ec0fc2de562407, this seems to be
another case where the backend was treating private functions
differently for no apparent reason.
This was particularly problematic for building the Zig compiler with
LLVM linked statically because we'd have enough such calls that linking
failed with thousands of these errors:
relocation R_MIPS_CALL16 out of range: 76048 is not in [-32768, 32767]
(cherry picked from commit 22371aefb10a31207de828cff7ef7511e9a552f7)
Added:
Modified:
llvm/lib/Target/Mips/Mips16ISelLowering.cpp
llvm/lib/Target/Mips/Mips16ISelLowering.h
llvm/lib/Target/Mips/MipsISelLowering.cpp
llvm/lib/Target/Mips/MipsISelLowering.h
llvm/lib/Target/Mips/MipsSEISelLowering.cpp
llvm/lib/Target/Mips/MipsSEISelLowering.h
llvm/test/CodeGen/Mips/private.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/Mips/Mips16ISelLowering.cpp b/llvm/lib/Target/Mips/Mips16ISelLowering.cpp
index ac32426288e08..122df08af99c1 100644
--- a/llvm/lib/Target/Mips/Mips16ISelLowering.cpp
+++ b/llvm/lib/Target/Mips/Mips16ISelLowering.cpp
@@ -355,12 +355,11 @@ static bool isMips16HardFloatLibcall(StringRef Name) {
*ParsedLibcalls.begin());
}
-void Mips16TargetLowering::
-getOpndList(SmallVectorImpl<SDValue> &Ops,
- std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
- bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
- SDValue Chain) const {
+void Mips16TargetLowering::getOpndList(
+ SmallVectorImpl<SDValue> &Ops,
+ std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
+ bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
+ CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
SelectionDAG &DAG = CLI.DAG;
MachineFunction &MF = DAG.getMachineFunction();
MipsFunctionInfo *FuncInfo = MF.getInfo<MipsFunctionInfo>();
@@ -443,7 +442,7 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
Ops.push_back(JumpTarget);
MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
- InternalLinkage, IsCallReloc, CLI, Callee,
+ LocalLinkage, IsCallReloc, CLI, Callee,
Chain);
}
diff --git a/llvm/lib/Target/Mips/Mips16ISelLowering.h b/llvm/lib/Target/Mips/Mips16ISelLowering.h
index 8f9f01b46b5a8..6913223d3e892 100644
--- a/llvm/lib/Target/Mips/Mips16ISelLowering.h
+++ b/llvm/lib/Target/Mips/Mips16ISelLowering.h
@@ -41,12 +41,11 @@ namespace llvm {
const char *getMips16HelperFunction
(Type* RetTy, ArgListTy &Args, bool &needHelper) const;
- void
- getOpndList(SmallVectorImpl<SDValue> &Ops,
- std::deque< std::pair<unsigned, SDValue> > &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
- bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
- SDValue Chain) const override;
+ void getOpndList(SmallVectorImpl<SDValue> &Ops,
+ std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
+ bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage,
+ bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
+ SDValue Chain) const override;
MachineBasicBlock *emitSel16(unsigned Opc, MachineInstr &MI,
MachineBasicBlock *BB) const;
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 5f5e5ba41ae00..1e059a6404e74 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -3171,15 +3171,14 @@ SDValue MipsTargetLowering::passArgOnStack(SDValue StackPtr, unsigned Offset,
MachineMemOperand::MOVolatile);
}
-void MipsTargetLowering::
-getOpndList(SmallVectorImpl<SDValue> &Ops,
- std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
- bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
- SDValue Chain) const {
+void MipsTargetLowering::getOpndList(
+ SmallVectorImpl<SDValue> &Ops,
+ std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
+ bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
+ CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
// Insert node "GP copy globalreg" before call to function.
//
- // R_MIPS_CALL* operators (emitted when non-internal functions are called
+ // R_MIPS_CALL* operators (emitted when non-local functions are called
// in PIC mode) allow symbols to be resolved via lazy binding.
// The lazy binding stub requires GP to point to the GOT.
// Note that we don't need GP to point to the GOT for indirect calls
@@ -3187,7 +3186,7 @@ getOpndList(SmallVectorImpl<SDValue> &Ops,
// lazy binding stub for a function only when R_MIPS_CALL* are the only relocs
// used for the function (that is, Mips linker doesn't generate lazy binding
// stub for a function whose address is taken in the program).
- if (IsPICCall && !InternalLinkage && IsCallReloc) {
+ if (IsPICCall && !LocalLinkage && IsCallReloc) {
unsigned GPReg = ABI.IsN64() ? Mips::GP_64 : Mips::GP;
EVT Ty = ABI.IsN64() ? MVT::i64 : MVT::i32;
RegsToPass.push_back(std::make_pair(GPReg, getGlobalReg(CLI.DAG, Ty)));
@@ -3571,7 +3570,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
}
}
- bool InternalLinkage = false;
+ bool LocalLinkage = false;
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
if (Subtarget.isTargetCOFF() &&
G->getGlobal()->hasDLLImportStorageClass()) {
@@ -3582,9 +3581,9 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
getDllimportSymbol(G, SDLoc(G), Ty, DAG), PtrInfo);
} else if (IsPIC) {
const GlobalValue *Val = G->getGlobal();
- InternalLinkage = Val->hasInternalLinkage();
+ LocalLinkage = Val->hasLocalLinkage();
- if (InternalLinkage)
+ if (LocalLinkage)
Callee = getAddrLocal(G, DL, Ty, DAG, ABI.IsN32() || ABI.IsN64());
else if (Subtarget.useXGOT()) {
Callee = getAddrGlobalLargeGOT(G, DL, Ty, DAG, MipsII::MO_CALL_HI16,
@@ -3625,7 +3624,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
SmallVector<SDValue, 8> Ops(1, Chain);
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
- getOpndList(Ops, RegsToPass, IsPIC, GlobalOrExternal, InternalLinkage,
+ getOpndList(Ops, RegsToPass, IsPIC, GlobalOrExternal, LocalLinkage,
IsCallReloc, CLI, Callee, Chain);
if (IsTailCall) {
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h b/llvm/lib/Target/Mips/MipsISelLowering.h
index 93d90f23b362e..eba86e5672961 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -308,7 +308,7 @@ using TargetRegisterClass = MCRegisterClass;
virtual void
getOpndList(SmallVectorImpl<SDValue> &Ops,
std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
+ bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage,
bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
SDValue Chain) const;
diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
index 628e8d4359f7c..b924ec5cde996 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
@@ -1343,15 +1343,14 @@ bool MipsSETargetLowering::isEligibleForTailCallOptimization(
return NextStackOffset <= FI.getIncomingArgSize();
}
-void MipsSETargetLowering::
-getOpndList(SmallVectorImpl<SDValue> &Ops,
- std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
- bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
- SDValue Chain) const {
+void MipsSETargetLowering::getOpndList(
+ SmallVectorImpl<SDValue> &Ops,
+ std::deque<std::pair<unsigned, SDValue>> &RegsToPass, bool IsPICCall,
+ bool GlobalOrExternal, bool LocalLinkage, bool IsCallReloc,
+ CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const {
Ops.push_back(Callee);
MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal,
- InternalLinkage, IsCallReloc, CLI, Callee,
+ LocalLinkage, IsCallReloc, CLI, Callee,
Chain);
}
diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.h b/llvm/lib/Target/Mips/MipsSEISelLowering.h
index 56b26b39f634d..fc10af7d186b4 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.h
@@ -68,12 +68,11 @@ using TargetRegisterClass = MCRegisterClass;
const CCState &CCInfo, unsigned NextStackOffset,
const MipsFunctionInfo &FI) const override;
- void
- getOpndList(SmallVectorImpl<SDValue> &Ops,
- std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
- bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage,
- bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
- SDValue Chain) const override;
+ void getOpndList(SmallVectorImpl<SDValue> &Ops,
+ std::deque<std::pair<unsigned, SDValue>> &RegsToPass,
+ bool IsPICCall, bool GlobalOrExternal, bool LocalLinkage,
+ bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee,
+ SDValue Chain) const override;
SDValue lowerR5900FPOp(SDValue Op, SelectionDAG &DAG,
RTLIB::Libcall LC) const;
diff --git a/llvm/test/CodeGen/Mips/private.ll b/llvm/test/CodeGen/Mips/private.ll
index be936ddde0072..1a81d381aa946 100644
--- a/llvm/test/CodeGen/Mips/private.ll
+++ b/llvm/test/CodeGen/Mips/private.ll
@@ -11,7 +11,8 @@ define private void @foo() {
define i32 @bar() {
; CHECK-LABEL: bar:
-; CHECK: call16($foo)
+; CHECK: lw $[[R1:[0-9]+]], %got($foo)($
+; CHECK: addiu $25, $[[R1]], %lo($foo)
; CHECK: lw $[[R0:[0-9]+]], %got($baz)($
; CHECK: lw ${{[0-9]+}}, %lo($baz)($[[R0]])
call void @foo()
More information about the llvm-branch-commits
mailing list