]> granicus.if.org Git - llvm/commitdiff
[MergeICmps] Make sorting strongly stable on the rhs.
authorClement Courbet <courbet@google.com>
Tue, 21 May 2019 17:58:42 +0000 (17:58 +0000)
committerClement Courbet <courbet@google.com>
Tue, 21 May 2019 17:58:42 +0000 (17:58 +0000)
Summary:
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.

Reviewers: gchatelet

Subscribers: hiraditya, llvm-commits, RKSimon

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D62193

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/MergeICmps.cpp

index 161e649581896a6362cdb11c7dad44cf80853707..a880e9e75783e762911b1209b4b9d433b56b9712 100644 (file)
@@ -507,7 +507,8 @@ BCECmpChain::BCECmpChain(const std::vector<BasicBlock *> &Blocks, PHINode &Phi,
   // semantics because we are only accessing dereferencable memory.
   llvm::sort(Comparisons_,
              [](const BCECmpBlock &LhsBlock, const BCECmpBlock &RhsBlock) {
-               return LhsBlock.Lhs() < RhsBlock.Lhs();
+               return std::tie(LhsBlock.Lhs(), LhsBlock.Rhs()) <
+                      std::tie(RhsBlock.Lhs(), RhsBlock.Rhs());
              });
 #ifdef MERGEICMPS_DOT_ON
   errs() << "AFTER REORDERING:\n\n";