Skip to content

Commit 679c3a1

Browse files
committed
[TargetLowering] use stable_sort to avoid nondeterminism
After 330fa7d we were seeing nondeterministic failures of llvm/test/CodeGen/ARM/thumb-big-stack.ll, with different code being generated in different runs. Switching sort -> stable_sort fixes this. It looks like the old algorithm picked the first best option, and using stable_sort restores that behavior.
1 parent fb8ce45 commit 679c3a1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5843,9 +5843,10 @@ TargetLowering::ConstraintGroup TargetLowering::getConstraintPreferences(
58435843
Ret.emplace_back(Code, CType);
58445844
}
58455845

5846-
std::sort(Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
5847-
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
5848-
});
5846+
std::stable_sort(
5847+
Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
5848+
return getConstraintPiority(a.second) > getConstraintPiority(b.second);
5849+
});
58495850

58505851
return Ret;
58515852
}

0 commit comments

Comments
 (0)