[llvm] [SROA] Use stable sort for slices to avoid non-determinism (PR #91609)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 08:53:20 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: None (henke9600)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/91609.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+2-5)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 096c6d1b1fad2..857cf6b77ea20 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -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());
+ llvm::stable_sort(Slices);
}
// Forward declare the iterator and range accessor for walking the
@@ -5122,7 +5119,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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/91609
More information about the llvm-commits
mailing list