Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7656,9 +7656,9 @@ unsigned Opcode = N->getOpcode(); // Canonicalize chains of this operation to LHS to allow the following fold. - if (N0.getOpcode() != Opcode && N1.getOpcode() == Opcode) - return DAG.getNode(Opcode, DL, VT, N1, N0); - + if (N1.getOpcode() == Opcode && N1.hasOneUse() && N0.getOpcode() != Opcode) + std::swap(N1, N0); + // Convert a chain of 3 dependent operations into 2 independent operations // and 1 dependent operation: // (op N0: (op N00: (op z, w), N01: y), N1: x) ->