Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -11728,23 +11728,34 @@ SDValue ReplStore; // Replace the chain to avoid dependency. - if (ST->isTruncatingStore()) { + if (ST->isTruncatingStore()) ReplStore = DAG.getTruncStore(BetterChain, SL, ST->getValue(), ST->getBasePtr(), ST->getMemoryVT(), ST->getMemOperand()); - } else { + else ReplStore = DAG.getStore(BetterChain, SL, ST->getValue(), ST->getBasePtr(), ST->getMemOperand()); + + unsigned Chain = (ST->getNumValues() > 1) ? 1 : 0; + + if (Chain) { + SDValue Base = ST->getBasePtr(); + ISD::MemIndexedMode AM = ST->getAddressingMode(); + SDValue Offset = ST->getOperand(3); + ReplStore = DAG.getIndexedStore(ReplStore, SL, Base, Offset, AM); } // Create token to keep both nodes around. SDValue Token = DAG.getNode(ISD::TokenFactor, SL, - MVT::Other, ST->getChain(), ReplStore); + MVT::Other, ST->getChain(), + ReplStore.getValue(Chain)); // Make sure the new and old chains are cleaned up. AddToWorklist(Token.getNode()); // Don't add users to work list. + if (Chain) + return CombineTo(ST, ReplStore, Token, false); return CombineTo(ST, Token, false); }