Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -11725,6 +11725,8 @@ SDLoc SL(ST); SDValue ReplStore; + unsigned Chain = (ST->getNumValues() > 1) ? 1 : 0; // Chain. + // Replace the chain to avoid dependency. if (ST->isTruncatingStore()) { ReplStore = DAG.getTruncStore(BetterChain, SL, ST->getValue(), @@ -11733,16 +11735,29 @@ } else { ReplStore = DAG.getStore(BetterChain, SL, ST->getValue(), ST->getBasePtr(), ST->getMemOperand()); + if (Chain) { + // Handle pre/post inc stores. + SDValue Base = ST->getBasePtr(); + ISD::MemIndexedMode AM = ST->getAddressingMode(); + SDValue Offset = ST->getOperand(3); + SDValue Temp = DAG.getIndexedStore(ReplStore, SL, Base, Offset, AM); + WorklistRemover DeadNodes(*this); + DAG.DeleteNode(ReplStore.getNode()); + ReplStore = Temp; + } } // 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); }