[PATCH] D39995: [SelectionDAG] Make sorting predicate stronger to remove non-deterministic ordering

Mandeep Singh Grang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 18 10:50:26 PST 2017


mgrang updated this revision to Diff 123464.
mgrang added a comment.

Added comment to explain what's going on.


Repository:
  rL LLVM

https://reviews.llvm.org/D39995

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp


Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9545,10 +9545,13 @@
   }
 
   if (TM.getOptLevel() != CodeGenOpt::None) {
-    // Order cases by probability so the most likely case will be checked first.
-    std::sort(W.FirstCluster, W.LastCluster + 1,
+	// Here, we order cases by probability so the most likely case will be
+	// checked first. However, two clusters can have the same probability in
+	// which case their relative ordering is non-deterministic. So we use Low
+	// as a tie-breaker as clusters are guaranteed to never overlap.
+	std::sort(W.FirstCluster, W.LastCluster + 1,
               [](const CaseCluster &a, const CaseCluster &b) {
-      return a.Prob > b.Prob;
+      return a.Prob != b.Prob ? a.Prob > b.Prob : a.Low < b.Low;
     });
 
     // Rearrange the case blocks so that the last one falls through if possible


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39995.123464.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171118/8207225b/attachment.bin>


More information about the llvm-commits mailing list