]> granicus.if.org Git - llvm/commitdiff
[mips] Fix return lowering
authorSimon Dardis <simon.dardis@imgtec.com>
Thu, 9 Mar 2017 11:19:48 +0000 (11:19 +0000)
committerSimon Dardis <simon.dardis@imgtec.com>
Thu, 9 Mar 2017 11:19:48 +0000 (11:19 +0000)
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!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297372 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MipsSEInstrInfo.cpp
test/CodeGen/Mips/return_address.ll
test/CodeGen/Mips/tnaked.ll

index ea703d0edd9638a764293257b922f8059eb6bb8a..91e712a7a54e8d15bd55bee542eb2a6fecab0c54 100644 (file)
@@ -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,
index 34b72baa6d25c79b06af10229cfad3fee462f5a1..54a106f4b349e7fdac82d97c5316328926710b4d 100644 (file)
@@ -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:
index 08f1ab5be86eefd2cbdd8d1056a1a5fc9d4102fc..7dff19c5d0009c88d5e310d1954c64fa56c3c928 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc -march=mipsel < %s | FileCheck %s
+; RUN: llc -march=mipsel < %s -verify-machineinstrs | FileCheck %s
 
 
 define void @tnaked() #0 {