Rematerialization logic was overly conservative when it comes to loads from fixed stack slots.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47529 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index a18f36a..2ff8afd 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -646,27 +646,9 @@
 
   int FrameIdx = 0;
   if (tii_->isLoadFromStackSlot(MI, FrameIdx) &&
-      mf_->getFrameInfo()->isImmutableObjectIndex(FrameIdx)) {
-    // This is a load from fixed stack slot. It can be rematerialized unless
-    // it's re-defined by a two-address instruction.
-    isLoad = true;
-    for (LiveInterval::const_vni_iterator i = li.vni_begin(), e = li.vni_end();
-         i != e; ++i) {
-      const VNInfo *VNI = *i;
-      if (VNI == ValNo)
-        continue;
-      unsigned DefIdx = VNI->def;
-      if (DefIdx == ~1U)
-        continue; // Dead val#.
-      MachineInstr *DefMI = (DefIdx == ~0u)
-        ? NULL : getInstructionFromIndex(DefIdx);
-      if (DefMI && DefMI->isRegReDefinedByTwoAddr(li.reg)) {
-        isLoad = false;
-        return false;
-      }
-    }
+      mf_->getFrameInfo()->isImmutableObjectIndex(FrameIdx))
+    // This is a load from fixed stack slot. It can be rematerialized.
     return true;
-  }
 
   if (tii_->isTriviallyReMaterializable(MI)) {
     isLoad = TID.isSimpleLoad();
@@ -754,6 +736,10 @@
     FoldOps.push_back(OpIdx);
   }
 
+  // Can't fold a load from fixed stack slot into a two address instruction.
+  if (isSS && DefMI && (MRInfo & VirtRegMap::isMod))
+    return false;
+
   MachineInstr *fmi = isSS ? tii_->foldMemoryOperand(*mf_, MI, FoldOps, Slot)
                            : tii_->foldMemoryOperand(*mf_, MI, FoldOps, DefMI);
   if (fmi) {