summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@mips.com>2011-12-09 01:45:12 +0000
committerAkira Hatanaka <ahatanaka@mips.com>2011-12-09 01:45:12 +0000
commit0dca9456c55787cd5a5f11b388aa76586b4fcdf6 (patch)
tree5d8aaa9c965f72a139c5c5531e97379b42ef33c9
parentf5b9a74f0a13afe3b7a8388be81e4062b63e4c30 (diff)
downloadllvm-0dca9456c55787cd5a5f11b388aa76586b4fcdf6.tar.gz
llvm-0dca9456c55787cd5a5f11b388aa76586b4fcdf6.tar.bz2
llvm-0dca9456c55787cd5a5f11b388aa76586b4fcdf6.tar.xz
jalr should use t9 ($25) for indirect calls regardless of the relocation model
specified. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146229 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/Mips/MipsISelLowering.cpp12
-rw-r--r--test/CodeGen/Mips/indirectcall.ll8
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp
index c888cfc4ca..a3dd45bd21 100644
--- a/lib/Target/Mips/MipsISelLowering.cpp
+++ b/lib/Target/Mips/MipsISelLowering.cpp
@@ -2338,7 +2338,7 @@ MipsTargetLowering::LowerCall(SDValue InChain, SDValue Callee,
// node so that legalize doesn't hack it.
unsigned char OpFlag;
bool IsPICCall = (IsN64 || IsPIC); // true if calls are translated to jalr $25
- bool LoadSymAddr = false;
+ bool GlobalOrExternal = false;
SDValue CalleeLo;
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
@@ -2355,7 +2355,7 @@ MipsTargetLowering::LowerCall(SDValue InChain, SDValue Callee,
getPointerTy(), 0, OpFlag);
}
- LoadSymAddr = true;
+ GlobalOrExternal = true;
}
else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
if (IsN64 || (!IsO32 && IsPIC))
@@ -2366,14 +2366,14 @@ MipsTargetLowering::LowerCall(SDValue InChain, SDValue Callee,
OpFlag = MipsII::MO_GOT_CALL;
Callee = DAG.getTargetExternalSymbol(S->getSymbol(),
getPointerTy(), OpFlag);
- LoadSymAddr = true;
+ GlobalOrExternal = true;
}
SDValue InFlag;
// Create nodes that load address of callee and copy it to T9
if (IsPICCall) {
- if (LoadSymAddr) {
+ if (GlobalOrExternal) {
// Load callee address
Callee = DAG.getNode(MipsISD::WrapperPIC, dl, getPointerTy(), Callee);
SDValue LoadValue = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
@@ -2387,7 +2387,11 @@ MipsTargetLowering::LowerCall(SDValue InChain, SDValue Callee,
} else
Callee = LoadValue;
}
+ }
+ // T9 should contain the address of the callee function if
+ // -reloction-model=pic or it is an indirect call.
+ if (IsPICCall || !GlobalOrExternal) {
// copy to T9
unsigned T9Reg = IsN64 ? Mips::T9_64 : Mips::T9;
Chain = DAG.getCopyToReg(Chain, dl, T9Reg, Callee, SDValue(0, 0));
diff --git a/test/CodeGen/Mips/indirectcall.ll b/test/CodeGen/Mips/indirectcall.ll
new file mode 100644
index 0000000000..ac565d6466
--- /dev/null
+++ b/test/CodeGen/Mips/indirectcall.ll
@@ -0,0 +1,8 @@
+; RUN: llc < %s -march=mipsel -relocation-model=static | FileCheck %s
+
+define void @foo0(void (i32)* nocapture %f1) nounwind {
+entry:
+; CHECK: jalr $25
+ tail call void %f1(i32 13) nounwind
+ ret void
+}