Skip to content

Commit e72209d

Browse files
authored
[MachineSink] Fix stable sort comparator (#116705)
Fix the comparator in `stable_sort()` to satisfy the strict weak ordering requirement. In #115367 this comparator was changed to use `getCycleDepth()` when `shouldOptimizeForSize()` is true. However, I mistakenly changed to logic so that we use `LHSFreq < RHSFreq` if **either** of them are zero. This causes us to fail the last requirment (https://en.cppreference.com/w/cpp/named_req/Compare). > if comp(a, b) == true and comp(b, c) == true then comp(a, c) == true
1 parent d29a50f commit e72209d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/CodeGen/MachineSink.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,8 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB,
12271227
AllSuccs, [&](const MachineBasicBlock *L, const MachineBasicBlock *R) {
12281228
uint64_t LHSFreq = MBFI ? MBFI->getBlockFreq(L).getFrequency() : 0;
12291229
uint64_t RHSFreq = MBFI ? MBFI->getBlockFreq(R).getFrequency() : 0;
1230-
if (llvm::shouldOptimizeForSize(MBB, PSI, MBFI) || !LHSFreq || !RHSFreq)
1230+
if (llvm::shouldOptimizeForSize(MBB, PSI, MBFI) ||
1231+
(!LHSFreq && !RHSFreq))
12311232
return CI->getCycleDepth(L) < CI->getCycleDepth(R);
12321233
return LHSFreq < RHSFreq;
12331234
});

0 commit comments

Comments
 (0)