Index: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp +++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp @@ -703,7 +703,7 @@ // Vector of PHIs contains PHIs for different instructions. // Sort the args according to their VNs, such that identical // instructions are together. - std::sort(CHIs.begin(), CHIs.end(), cmpVN); + std::stable_sort(CHIs.begin(), CHIs.end(), cmpVN); auto TI = BB->getTerminator(); auto B = CHIs.begin(); // [PreIt, PHIIt) form a range of CHIs which have identical VNs.