GNU as refuses to assemble "pop {}" instruction. Do not emit such
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 16 Jun 2009 18:49:08 +0000 (18:49 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 16 Jun 2009 18:49:08 +0000 (18:49 +0000)
(this is the case when we have thumb vararg function with single
callee-saved register, which is handled separately).

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

lib/Target/ARM/ARMInstrInfo.cpp
test/CodeGen/ARM/vargs2.ll

index 4b0dbb5dacdb668e9a0d75e51a8b768f360a75f7..d19fb8eea87f6dec6172a2b024ec78ef841dffcf 100644 (file)
@@ -697,7 +697,6 @@ restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
 
   bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
   MachineInstr *PopMI = MF.CreateMachineInstr(get(ARM::tPOP),MI->getDebugLoc());
-  MBB.insert(MI, PopMI);
   for (unsigned i = CSI.size(); i != 0; --i) {
     unsigned Reg = CSI[i-1].getReg();
     if (Reg == ARM::LR) {
@@ -706,10 +705,15 @@ restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
         continue;
       Reg = ARM::PC;
       PopMI->setDesc(get(ARM::tPOP_RET));
-      MBB.erase(MI);
+      MI = MBB.erase(MI);
     }
     PopMI->addOperand(MachineOperand::CreateReg(Reg, true));
   }
+
+  // It's illegal to emit pop instruction without operands.
+  if (PopMI->getNumOperands() > 0)
+    MBB.insert(MI, PopMI);
+
   return true;
 }
 
index fb0b8d8ef7cb483126c2d66088fbab80070a79d8..56169100fc79c6c7865cebffc79ff622ad3ebbc6 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | llc -march=thumb
 ; RUN: llvm-as < %s | llc -march=thumb | \
-; RUN:   grep pop | count 2
+; RUN:   grep pop | count 1
 
 @str = internal constant [4 x i8] c"%d\0A\00"           ; <[4 x i8]*> [#uses=1]