Skip to content

Commit d03bd8a

Browse files
committed
[SROA] Use stable sort for slices to avoid non-determinism
The use of unstable sorting here was found to cause non-deterministic output.
1 parent 139e0aa commit d03bd8a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,8 @@ class AllocaSlices {
627627
/// everything so that the usual ordering properties of the alloca's slices
628628
/// hold.
629629
void insert(ArrayRef<Slice> NewSlices) {
630-
int OldSize = Slices.size();
631630
Slices.append(NewSlices.begin(), NewSlices.end());
632-
auto SliceI = Slices.begin() + OldSize;
633-
llvm::sort(SliceI, Slices.end());
634-
std::inplace_merge(Slices.begin(), SliceI, Slices.end());
631+
llvm::stable_sort(Slices);
635632
}
636633

637634
// Forward declare the iterator and range accessor for walking the
@@ -5122,7 +5119,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
51225119
}
51235120

51245121
if (!IsSorted)
5125-
llvm::sort(AS);
5122+
llvm::stable_sort(AS);
51265123

51275124
/// Describes the allocas introduced by rewritePartition in order to migrate
51285125
/// the debug info.

0 commit comments

Comments
 (0)