[llvm] [SROA] Use stable sort for slices to avoid non-determinism (PR #91609)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 14 18:07:32 PDT 2024


================
@@ -627,11 +627,8 @@ class AllocaSlices {
   /// everything so that the usual ordering properties of the alloca's slices
   /// hold.
   void insert(ArrayRef<Slice> NewSlices) {
-    int OldSize = Slices.size();
     Slices.append(NewSlices.begin(), NewSlices.end());
-    auto SliceI = Slices.begin() + OldSize;
-    llvm::sort(SliceI, Slices.end());
-    std::inplace_merge(Slices.begin(), SliceI, Slices.end());
----------------
nikic wrote:

Yeah, that's right. `llvm::stable_sort` is just a thin wrapper around `std::stable_sort` that calls begin() and end() on the container. When passing explicit iterators you use `std::stable_sort`.

(`llvm::sort` is different, because it also has a special POD sort implementation.)

https://github.com/llvm/llvm-project/pull/91609


More information about the llvm-commits mailing list