From: Clement Courbet Date: Tue, 21 May 2019 17:58:42 +0000 (+0000) Subject: [MergeICmps] Make sorting strongly stable on the rhs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e6de4e0a2b1af5d7c3c3286b39eddcb352871f1;p=llvm [MergeICmps] Make sorting strongly stable on the rhs. 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 --- diff --git a/lib/Transforms/Scalar/MergeICmps.cpp b/lib/Transforms/Scalar/MergeICmps.cpp index 161e6495818..a880e9e7578 100644 --- a/lib/Transforms/Scalar/MergeICmps.cpp +++ b/lib/Transforms/Scalar/MergeICmps.cpp @@ -507,7 +507,8 @@ BCECmpChain::BCECmpChain(const std::vector &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";