From dcab2a544c2e4805fea8c7b55130c16d6aa000cb Mon Sep 17 00:00:00 2001 From: Simon Dardis Date: Thu, 9 Mar 2017 11:19:48 +0000 Subject: [PATCH] [mips] Fix return lowering Fix a machine verifier issue where a instruction was using a invalid register. The return pseudo is expanded and has the return address register added to it. The return register may have been spuriously mark as killed earlier. This partially resolves PR/27458 Thanks to Quentin Colombet for reporting the issue! llvm-svn: 297372 --- lib/Target/Mips/MipsSEInstrInfo.cpp | 15 ++++++++++++--- test/CodeGen/Mips/return_address.ll | 2 +- test/CodeGen/Mips/tnaked.ll | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/Target/Mips/MipsSEInstrInfo.cpp b/lib/Target/Mips/MipsSEInstrInfo.cpp index ea703d0edd9..91e712a7a54 100644 --- a/lib/Target/Mips/MipsSEInstrInfo.cpp +++ b/lib/Target/Mips/MipsSEInstrInfo.cpp @@ -540,11 +540,20 @@ unsigned MipsSEInstrInfo::getAnalyzableBrOpc(unsigned Opc) const { void MipsSEInstrInfo::expandRetRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const { + + MachineInstrBuilder MIB; if (Subtarget.isGP64bit()) - BuildMI(MBB, I, I->getDebugLoc(), get(Mips::PseudoReturn64)) - .addReg(Mips::RA_64); + MIB = BuildMI(MBB, I, I->getDebugLoc(), get(Mips::PseudoReturn64)) + .addReg(Mips::RA_64, RegState::Undef); else - BuildMI(MBB, I, I->getDebugLoc(), get(Mips::PseudoReturn)).addReg(Mips::RA); + MIB = BuildMI(MBB, I, I->getDebugLoc(), get(Mips::PseudoReturn)) + .addReg(Mips::RA, RegState::Undef); + + // Retain any imp-use flags. + for (auto & MO : I->operands()) { + if (MO.isImplicit()) + MIB.add(MO); + } } void MipsSEInstrInfo::expandERet(MachineBasicBlock &MBB, diff --git a/test/CodeGen/Mips/return_address.ll b/test/CodeGen/Mips/return_address.ll index 34b72baa6d2..54a106f4b34 100644 --- a/test/CodeGen/Mips/return_address.ll +++ b/test/CodeGen/Mips/return_address.ll @@ -1,4 +1,4 @@ -; RUN: llc -march=mipsel < %s | FileCheck %s +; RUN: llc -march=mipsel -verify-machineinstrs < %s | FileCheck %s define i8* @f1() nounwind { entry: diff --git a/test/CodeGen/Mips/tnaked.ll b/test/CodeGen/Mips/tnaked.ll index 08f1ab5be86..7dff19c5d00 100644 --- a/test/CodeGen/Mips/tnaked.ll +++ b/test/CodeGen/Mips/tnaked.ll @@ -1,4 +1,4 @@ -; RUN: llc -march=mipsel < %s | FileCheck %s +; RUN: llc -march=mipsel < %s -verify-machineinstrs | FileCheck %s define void @tnaked() #0 {