Sometimes a MI can define a register as well as defining a super-register at the
same time. Do not mark the "smaller" def as dead.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41871 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LiveVariables.cpp b/lib/CodeGen/LiveVariables.cpp
index e8d07bf..97e8671 100644
--- a/lib/CodeGen/LiveVariables.cpp
+++ b/lib/CodeGen/LiveVariables.cpp
@@ -249,9 +249,6 @@
 }
 
 void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) {
-  // There is a now a proper use, forget about the last partial use.
-  PhysRegPartUse[Reg] = NULL;
-
   // Turn previous partial def's into read/mod/write.
   for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) {
     MachineInstr *Def = PhysRegPartDef[Reg][i];
@@ -266,12 +263,15 @@
   // A: EAX = ...
   // B:     = AX
   // Add implicit def to A.
-  if (PhysRegInfo[Reg] && !PhysRegUsed[Reg]) {
+  if (PhysRegInfo[Reg] && PhysRegInfo[Reg] != PhysRegPartUse[Reg] &&
+      !PhysRegUsed[Reg]) {
     MachineInstr *Def = PhysRegInfo[Reg];
     if (!Def->findRegisterDefOperand(Reg))
       Def->addRegOperand(Reg, true/*IsDef*/,true/*IsImp*/);
   }
 
+  // There is a now a proper use, forget about the last partial use.
+  PhysRegPartUse[Reg] = NULL;
   PhysRegInfo[Reg] = MI;
   PhysRegUsed[Reg] = true;
 
@@ -373,7 +373,8 @@
       } else if (PhysRegPartUse[SubReg])
         // Add implicit use / kill to last use of a sub-register.
         addRegisterKilled(SubReg, PhysRegPartUse[SubReg], true);
-      else
+      else if (LastRef != MI)
+        // This must be a def of the subreg on the same MI.
         addRegisterDead(SubReg, LastRef);
     }
   }
@@ -381,7 +382,7 @@
   if (MI) {
     for (const unsigned *SuperRegs = RegInfo->getSuperRegisters(Reg);
          unsigned SuperReg = *SuperRegs; ++SuperRegs) {
-      if (PhysRegInfo[SuperReg]) {
+      if (PhysRegInfo[SuperReg] && PhysRegInfo[SuperReg] != MI) {
         // The larger register is previously defined. Now a smaller part is
         // being re-defined. Treat it as read/mod/write.
         // EAX =