[llvm] 679c3a1 - [TargetLowering] use stable_sort to avoid nondeterminism

Sam McCall via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 06:16:19 PDT 2023


Author: Sam McCall
Date: 2023-09-26T15:16:09+02:00
New Revision: 679c3a1791b51f2ad0771b8ce924130b071a956f

URL: https://github.com/llvm/llvm-project/commit/679c3a1791b51f2ad0771b8ce924130b071a956f
DIFF: https://github.com/llvm/llvm-project/commit/679c3a1791b51f2ad0771b8ce924130b071a956f.diff

LOG: [TargetLowering] use stable_sort to avoid nondeterminism

After 330fa7d2a4e0cfbb4b078 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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 6aaaa2f68638c7d..3b259d99f0029ca 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5843,9 +5843,10 @@ TargetLowering::ConstraintGroup TargetLowering::getConstraintPreferences(
     Ret.emplace_back(Code, CType);
   }
 
-  std::sort(Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
-    return getConstraintPiority(a.second) > getConstraintPiority(b.second);
-  });
+  std::stable_sort(
+      Ret.begin(), Ret.end(), [](ConstraintPair a, ConstraintPair b) {
+        return getConstraintPiority(a.second) > getConstraintPiority(b.second);
+      });
 
   return Ret;
 }


        


More information about the llvm-commits mailing list