[GVNHoist] Fix non-deterministic sort order of PHIs for identical instructions
authorMandeep Singh Grang <mgrang@codeaurora.org>
Mon, 30 Oct 2017 19:42:41 +0000 (19:42 +0000)
committerMandeep Singh Grang <mgrang@codeaurora.org>
Mon, 30 Oct 2017 19:42:41 +0000 (19:42 +0000)
Summary: This fixes failure in Transforms/GVNHoist/hoist.ll uncovered by D39245.

Reviewers: hiraditya, spop, dberlin

Reviewed By: dberlin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D39410

llvm-svn: 316949

llvm/lib/Transforms/Scalar/GVNHoist.cpp

index c13768d..d77ebdc 100644 (file)
@@ -703,7 +703,7 @@ private:
       // 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.