From: Vasileios Kalintiris Date: Sat, 18 Jun 2016 15:39:43 +0000 (+0000) Subject: [mips] Emit a JALR with $rd equal to $zero, instead of a JR in MIPS32R6. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76bbc90afa0be2cb0a0cdca190271b9024a66351;p=llvm [mips] Emit a JALR with $rd equal to $zero, instead of a JR in MIPS32R6. Summary: JR is an alias of JALR with $rd=0 in the R6 ISA. Also, this fixes recursive builds in MIPS32R6. Reviewers: dsanders, sdardis Subscribers: jfb, dschuff, dsanders, sdardis, llvm-commits Differential Revision: http://reviews.llvm.org/D21370 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273085 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Mips/MipsLongBranch.cpp b/lib/Target/Mips/MipsLongBranch.cpp index 9640408e1cc..8a48d863c8b 100644 --- a/lib/Target/Mips/MipsLongBranch.cpp +++ b/lib/Target/Mips/MipsLongBranch.cpp @@ -335,23 +335,26 @@ void MipsLongBranch::expandToLongBranch(MBBInfo &I) { BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::LW), Mips::RA) .addReg(Mips::SP).addImm(0); - if (!Subtarget.isTargetNaCl()) { - MIBundleBuilder(*BalTgtMBB, Pos) - .append(BuildMI(*MF, DL, TII->get(Mips::JR)).addReg(Mips::AT)) - .append(BuildMI(*MF, DL, TII->get(Mips::ADDiu), Mips::SP) - .addReg(Mips::SP).addImm(8)); - } else { - // In NaCl, modifying the sp is not allowed in branch delay slot. + // In NaCl, modifying the sp is not allowed in branch delay slot. + if (Subtarget.isTargetNaCl()) BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::ADDiu), Mips::SP) .addReg(Mips::SP).addImm(8); - MIBundleBuilder(*BalTgtMBB, Pos) - .append(BuildMI(*MF, DL, TII->get(Mips::JR)).addReg(Mips::AT)) - .append(BuildMI(*MF, DL, TII->get(Mips::NOP))); + if (Subtarget.hasMips32r6()) + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JALR)) + .addReg(Mips::ZERO).addReg(Mips::AT); + else + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JR)).addReg(Mips::AT); + if (Subtarget.isTargetNaCl()) { + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::NOP)); // Bundle-align the target of indirect branch JR. TgtMBB->setAlignment(MIPS_NACL_BUNDLE_ALIGN); - } + } else + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::ADDiu), Mips::SP) + .addReg(Mips::SP).addImm(8); + + BalTgtMBB->rbegin()->bundleWithPred(); } else { // $longbr: // daddiu $sp, $sp, -16 @@ -410,10 +413,15 @@ void MipsLongBranch::expandToLongBranch(MBBInfo &I) { BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::LD), Mips::RA_64) .addReg(Mips::SP_64).addImm(0); - MIBundleBuilder(*BalTgtMBB, Pos) - .append(BuildMI(*MF, DL, TII->get(Mips::JR64)).addReg(Mips::AT_64)) - .append(BuildMI(*MF, DL, TII->get(Mips::DADDiu), Mips::SP_64) - .addReg(Mips::SP_64).addImm(16)); + if (Subtarget.hasMips64r6()) + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JALR64)) + .addReg(Mips::ZERO_64).addReg(Mips::AT_64); + else + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::JR64)).addReg(Mips::AT_64); + + BuildMI(*BalTgtMBB, Pos, DL, TII->get(Mips::DADDiu), Mips::SP_64) + .addReg(Mips::SP_64).addImm(16); + BalTgtMBB->rbegin()->bundleWithPred(); } assert(LongBrMBB->size() + BalTgtMBB->size() == LongBranchSeqSize); diff --git a/test/CodeGen/Mips/longbranch.ll b/test/CodeGen/Mips/longbranch.ll index d2eabf87ce7..06eda11e788 100644 --- a/test/CodeGen/Mips/longbranch.ll +++ b/test/CodeGen/Mips/longbranch.ll @@ -1,10 +1,14 @@ ; RUN: llc -march=mipsel -relocation-model=pic < %s | FileCheck %s ; RUN: llc -march=mipsel -force-mips-long-branch -O3 -relocation-model=pic < %s \ ; RUN: | FileCheck %s -check-prefix=O32 +; RUN: llc -march=mipsel -mcpu=mips32r6 -force-mips-long-branch -O3 \ +; RUN: -relocation-model=pic -asm-show-inst < %s | FileCheck %s -check-prefix=O32-R6 ; RUN: llc -march=mips64el -mcpu=mips4 -target-abi=n64 -force-mips-long-branch -O3 -relocation-model=pic \ ; RUN: < %s | FileCheck %s -check-prefix=N64 ; RUN: llc -march=mips64el -mcpu=mips64 -target-abi=n64 -force-mips-long-branch -O3 -relocation-model=pic \ ; RUN: < %s | FileCheck %s -check-prefix=N64 +; RUN: llc -march=mips64el -mcpu=mips64r6 -target-abi=n64 -force-mips-long-branch -O3 \ +; RUN: -relocation-model=pic -asm-show-inst < %s | FileCheck %s -check-prefix=N64-R6 ; RUN: llc -march=mipsel -mcpu=mips32r2 -mattr=micromips \ ; RUN: -force-mips-long-branch -O3 -relocation-model=pic < %s | FileCheck %s -check-prefix=MICROMIPS ; RUN: llc -mtriple=mipsel-none-nacl -force-mips-long-branch -O3 -relocation-model=pic < %s \ @@ -72,6 +76,10 @@ end: ; O32: jr $ra ; O32: nop +; In MIPS32R6 JR is an alias to JALR with $rd=0. As everything else remains the +; same with the O32 prefix, we use -asm-show-inst in order to make sure that +; the opcode of the MachineInst is a JALR. +; O32-R6: JALR ; Check the MIPS64 version. @@ -101,6 +109,11 @@ end: ; N64: jr $ra ; N64: nop +; In MIPS64R6 JR is an alias to JALR with $rd=0. As everything else remains the +; same with the N64 prefix, we use -asm-show-inst in order to make sure that +; the opcode of the MachineInst is a JALR. +; N64-R6: JALR64 + ; Check the microMIPS version.