It's not safe to fold a load from GV stub or constantpool into a two-address use.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49002 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index 621c83d..f29b61b 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -757,8 +757,9 @@
   if (FilterFoldedOps(MI, Ops, MRInfo, FoldOps))
     return false;
 
-  // Can't fold a load from fixed stack slot into a two address instruction.
-  if (isSS && DefMI && (MRInfo & VirtRegMap::isMod))
+  // The only time it's safe to fold into a two address instruction is when
+  // it's folding reload and spill from / into a spill stack slot.
+  if (DefMI && (MRInfo & VirtRegMap::isMod))
     return false;
 
   MachineInstr *fmi = isSS ? tii_->foldMemoryOperand(*mf_, MI, FoldOps, Slot)
diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp
index ffe2083..8a54645 100644
--- a/lib/Target/X86/X86InstrInfo.cpp
+++ b/lib/Target/X86/X86InstrInfo.cpp
@@ -1825,7 +1825,15 @@
       MI->getOperand(0).getReg() == MI->getOperand(1).getReg()) { 
     OpcodeTablePtr = &RegOp2MemOpTable2Addr;
     isTwoAddrFold = true;
+    // Can't write back to CPI or a GV stub.
+    if (MOs[3].isCPI() ||
+        (MOs[3].isGlobal() && isGVStub(MOs[3].getGlobal(), TM)))
+      return NULL;
   } else if (i == 0) { // If operand 0
+    // Can't write back to CPI or a GV stub.
+    if (MOs[3].isCPI() ||
+        (MOs[3].isGlobal() && isGVStub(MOs[3].getGlobal(), TM)))
+      return NULL;
     if (MI->getOpcode() == X86::MOV16r0)
       NewMI = MakeM0Inst(*this, X86::MOV16mi, MOs, MI);
     else if (MI->getOpcode() == X86::MOV32r0)