Index: lib/CodeGen/RegAllocFast.cpp =================================================================== --- lib/CodeGen/RegAllocFast.cpp +++ lib/CodeGen/RegAllocFast.cpp @@ -317,6 +317,17 @@ LiveReg &LR = *LRI; assert(PhysRegState[LR.PhysReg] == LRI->VirtReg && "Broken RegState mapping"); + const BasicBlock *BB = MBB->getBasicBlock(); + if (BB) { + const Function *F = BB->getParent(); + if (F && F->hasFnAttribute(Attribute::Naked)) { + killVirtReg(LRI); + DEBUG(dbgs() << "Function is naked, disable register spilling " + << printReg(LRI->VirtReg, TRI) << " in " + << printReg(LR.PhysReg, TRI)); + return; + } + } if (LR.Dirty) { // If this physreg is used by the instruction, we want to kill it on the // instruction, not on the spill.