Skip to content

Commit 50dbbe5

Browse files
authored
[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.
1 parent e3ffc4b commit 50dbbe5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class AllocaSlices {
630630
int OldSize = Slices.size();
631631
Slices.append(NewSlices.begin(), NewSlices.end());
632632
auto SliceI = Slices.begin() + OldSize;
633-
llvm::sort(SliceI, Slices.end());
633+
std::stable_sort(SliceI, Slices.end());
634634
std::inplace_merge(Slices.begin(), SliceI, Slices.end());
635635
}
636636

@@ -5122,7 +5122,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
51225122
}
51235123

51245124
if (!IsSorted)
5125-
llvm::sort(AS);
5125+
llvm::stable_sort(AS);
51265126

51275127
/// Describes the allocas introduced by rewritePartition in order to migrate
51285128
/// the debug info.

0 commit comments

Comments
 (0)