diff --git a/llvm/lib/Transforms/Scalar/LoopSink.cpp b/llvm/lib/Transforms/Scalar/LoopSink.cpp --- a/llvm/lib/Transforms/Scalar/LoopSink.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSink.cpp @@ -222,9 +222,11 @@ // order. No need to stable sort as the block numbers are a total ordering. SmallVector<BasicBlock *, 2> SortedBBsToSinkInto; llvm::append_range(SortedBBsToSinkInto, BBsToSinkInto); - llvm::sort(SortedBBsToSinkInto, [&](BasicBlock *A, BasicBlock *B) { - return LoopBlockNumber.find(A)->second < LoopBlockNumber.find(B)->second; - }); + if (SortedBBsToSinkInto.size() > 1) { + llvm::sort(SortedBBsToSinkInto, [&](BasicBlock *A, BasicBlock *B) { + return LoopBlockNumber.find(A)->second < LoopBlockNumber.find(B)->second; + }); + } BasicBlock *MoveBB = *SortedBBsToSinkInto.begin(); // FIXME: Optimize the efficiency for cloned value replacement. The current