[llvm] [CodeLayout] Faster basic block reordering, ext-tsp (PR #68617)

Rahman Lavaee via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 11:15:50 PDT 2023


================
@@ -699,28 +719,44 @@ class ExtTSPImpl {
     /// Deterministically compare pairs of chains.
     auto compareChainPairs = [](const ChainT *A1, const ChainT *B1,
                                 const ChainT *A2, const ChainT *B2) {
-      if (A1 != A2)
-        return A1->Id < A2->Id;
-      return B1->Id < B2->Id;
+      return std::make_tuple(A1->Id, B1->Id) < std::make_tuple(A2->Id, B2->Id);
     };
 
+    double PrevScore = 1e9;
     while (HotChains.size() > 1) {
       ChainT *BestChainPred = nullptr;
       ChainT *BestChainSucc = nullptr;
       MergeGainT BestGain;
       // Iterate over all pairs of chains.
       for (ChainT *ChainPred : HotChains) {
+        // Since the score of merging doesn't increase, we can stop early when
----------------
rlavaee wrote:

Is this always true? What if merging two chains A and B allows the total gain of merging <A.B> with another chain C to increase because both A and B have branches to C?

https://github.com/llvm/llvm-project/pull/68617


More information about the llvm-commits mailing list