diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -1206,6 +1206,11 @@ UsedRegs.set(Reg); } + // Get a list of registers that are used. + BitVector LiveIns(TRI.getNumRegs()); + for (const MachineBasicBlock::RegisterMaskPair &LI : MF.front().liveins()) + LiveIns.set(LI.PhysReg); + BitVector RegsToZero(TRI.getNumRegs()); for (MCRegister Reg : AllocatableSet.set_bits()) { // Skip over fixed registers. @@ -1221,8 +1226,14 @@ continue; // Want only registers used for arguments. - if (OnlyArg && !TRI.isArgumentRegister(MF, Reg)) - continue; + if (OnlyArg) { + if (OnlyUsed) { + if (!LiveIns[Reg]) + continue; + } else if (!TRI.isArgumentRegister(MF, Reg)) { + continue; + } + } RegsToZero.set(Reg); }