diff --git a/llvm/lib/CodeGen/RegisterScavenging.cpp b/llvm/lib/CodeGen/RegisterScavenging.cpp index 2cd5233f5930..34302a0cac6b 100644 --- a/llvm/lib/CodeGen/RegisterScavenging.cpp +++ b/llvm/lib/CodeGen/RegisterScavenging.cpp @@ -438,7 +438,8 @@ unsigned RegScavenger::scavengeRegister(const TargetRegisterClass *RC, // otherwise, use the emergency stack spill slot. if (!TRI->saveScavengerRegister(*MBB, I, UseMI, RC, SReg)) { // Spill the scavenged register before I. - if (Scavenged[SI].FrameIndex < 0) { + int FI = Scavenged[SI].FrameIndex; + if (FI < FIB || FI >= FIE) { Twine Msg = Twine("Error while trying to spill ") + TRI->getName(SReg) + " from class " + TRI->getRegClassName(RC) + ": Cannot scavenge register without an emergency spill slot!";