Fix PR2596: out of bound reference.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54375 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp
index b9e96b1..c06ff71 100644
--- a/lib/CodeGen/VirtRegMap.cpp
+++ b/lib/CodeGen/VirtRegMap.cpp
@@ -560,8 +560,11 @@
     if (!MO.isRegister() || !MO.isUse() || !MO.isKill())
       continue;
     unsigned Reg = MO.getReg();
+    if (TargetRegisterInfo::isVirtualRegister(Reg))
+      continue;
     if (KillRegs)
       KillRegs->push_back(Reg);
+    assert(Reg < KillOps.size());
     if (KillOps[Reg] == &MO) {
       RegKills.reset(Reg);
       KillOps[Reg] = NULL;
@@ -943,9 +946,11 @@
         return false;
       continue;
     }
-    PhysReg = VRM.getPhys(VirtReg);
-    if (!TRI->regsOverlap(PhysReg, UnfoldPR))
-      continue;
+    if (VRM.hasPhys(VirtReg)) {
+      PhysReg = VRM.getPhys(VirtReg);
+      if (!TRI->regsOverlap(PhysReg, UnfoldPR))
+        continue;
+    }
 
     // Ok, we'll need to reload the value into a register which makes
     // it impossible to perform the store unfolding optimization later.