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

via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 23:17:48 PDT 2024


Author: henke9600
Date: 2024-05-21T08:17:44+02:00
New Revision: 50dbbe5a0afd76f3c26c03da5af65e7263ac8664

URL: https://github.com/llvm/llvm-project/commit/50dbbe5a0afd76f3c26c03da5af65e7263ac8664
DIFF: https://github.com/llvm/llvm-project/commit/50dbbe5a0afd76f3c26c03da5af65e7263ac8664.diff

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

Found this while trying to build a LLVM toolchain reproducibly from both
Debian 12 and FreeBSD 14. With these changes they come out bit-by-bit
identical.

Previously there was a mix of stable and unstable sorts for slices, now
only stable sorts are used.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SROA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 096c6d1b1fad2..756daf5bb41fa 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -630,7 +630,7 @@ class AllocaSlices {
     int OldSize = Slices.size();
     Slices.append(NewSlices.begin(), NewSlices.end());
     auto SliceI = Slices.begin() + OldSize;
-    llvm::sort(SliceI, Slices.end());
+    std::stable_sort(SliceI, Slices.end());
     std::inplace_merge(Slices.begin(), SliceI, Slices.end());
   }
 
@@ -5122,7 +5122,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
   }
 
   if (!IsSorted)
-    llvm::sort(AS);
+    llvm::stable_sort(AS);
 
   /// Describes the allocas introduced by rewritePartition in order to migrate
   /// the debug info.


        


More information about the llvm-commits mailing list