[PATCH] D62193: [MergeICmps] Make sorting strongly stable on the rhs.

Clement Courbet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 06:45:27 PDT 2019


courbet created this revision.
courbet added a reviewer: gchatelet.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

Because the sort order was not strongly stable on the RHS, whether the
chain could merge would depend on the order of the blocks in the Phi.

EXPENSIVE_CHECKS would shuffle the blocks before sorting, resulting in
non-deterministic merging.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62193

Files:
  llvm/lib/Transforms/Scalar/MergeICmps.cpp


Index: llvm/lib/Transforms/Scalar/MergeICmps.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -521,7 +521,8 @@
   // semantics because we are only accessing dereferencable memory.
   llvm::sort(Comparisons_,
              [](const BCECmpBlock &LhsBlock, const BCECmpBlock &RhsBlock) {
-               return LhsBlock.Rhs() < RhsBlock.Lhs();
+               return std::tie(LhsBlock.Lhs(), LhsBlock.Rhs()) <
+                      std::tie(RhsBlock.Lhs(), RhsBlock.Rhs());
              });
 #ifdef MERGEICMPS_DOT_ON
   errs() << "AFTER REORDERING:\n\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62193.200490.patch
Type: text/x-patch
Size: 672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190521/656f67a8/attachment.bin>


More information about the llvm-commits mailing list