diff options
author | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2024-11-19 16:15:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 16:15:35 -0800 |
commit | e72209db3586ee03f433fe30c3bfac6c9c4d9d6f (patch) | |
tree | 1172d3fa7ad95883b3952842d50c6eeaea5311a9 /llvm/lib/CodeGen/MachineSink.cpp | |
parent | d29a50f358e71a695b23e456d66ed2924617deb9 (diff) | |
download | llvm-e72209db3586ee03f433fe30c3bfac6c9c4d9d6f.zip llvm-e72209db3586ee03f433fe30c3bfac6c9c4d9d6f.tar.gz llvm-e72209db3586ee03f433fe30c3bfac6c9c4d9d6f.tar.bz2 |
[MachineSink] Fix stable sort comparator (#116705)
Fix the comparator in `stable_sort()` to satisfy the strict weak
ordering requirement.
In https://github.com/llvm/llvm-project/pull/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
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineSink.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index c470bd7..0def107 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -1227,7 +1227,8 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB, AllSuccs, [&](const MachineBasicBlock *L, const MachineBasicBlock *R) { uint64_t LHSFreq = MBFI ? MBFI->getBlockFreq(L).getFrequency() : 0; uint64_t RHSFreq = MBFI ? MBFI->getBlockFreq(R).getFrequency() : 0; - if (llvm::shouldOptimizeForSize(MBB, PSI, MBFI) || !LHSFreq || !RHSFreq) + if (llvm::shouldOptimizeForSize(MBB, PSI, MBFI) || + (!LHSFreq && !RHSFreq)) return CI->getCycleDepth(L) < CI->getCycleDepth(R); return LHSFreq < RHSFreq; }); |