Fix X86's unfoldMemoryOperand to properly handle MachineMemOperands.
authorDan Gohman <gohman@apple.com>
Wed, 23 Sep 2009 01:29:41 +0000 (01:29 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 23 Sep 2009 01:29:41 +0000 (01:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82597 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86InstrInfo.cpp

index e55aa1e9bbd5387d04ac4fb57442683f95a65947..fb26c5ce4edac5bcc5db02a5ab712910ed38beef 100644 (file)
@@ -2567,7 +2567,7 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
   std::vector<SDValue> AfterOps;
   DebugLoc dl = N->getDebugLoc();
   unsigned NumOps = N->getNumOperands();
-  for (unsigned i = 0; i != NumOps-1; ++i) {
+  for (unsigned i = 0; i != NumOps-2; ++i) {
     SDValue Op = N->getOperand(i);
     if (i >= Index-NumDefs && i < Index-NumDefs + X86AddrNumOperands)
       AddrOps.push_back(Op);
@@ -2576,6 +2576,8 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
     else if (i > Index-NumDefs)
       AfterOps.push_back(Op);
   }
+  SDValue MemOp = N->getOperand(NumOps-2);
+  AddrOps.push_back(MemOp);
   SDValue Chain = N->getOperand(NumOps-1);
   AddrOps.push_back(Chain);
 
@@ -2612,8 +2614,10 @@ X86InstrInfo::unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
 
   // Emit the store instruction.
   if (FoldedStore) {
+    AddrOps.pop_back();
     AddrOps.pop_back();
     AddrOps.push_back(SDValue(NewNode, 0));
+    AddrOps.push_back(MemOp);
     AddrOps.push_back(Chain);
     bool isAligned = (RI.getStackAlignment() >= 16) ||
       RI.needsStackRealignment(MF);