[llvm] [llvm] Use std::tie to implement comparison functors (NFC) (PR #141353)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 08:24:55 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/141353.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/IPO/SampleProfile.cpp (+1-3) 
- (modified) llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp (+1-5) 


``````````diff
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 616eeae3b1fec..000b3ccbb3cbc 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -897,9 +897,7 @@ updateIDTMetaData(Instruction &Inst,
 
   llvm::sort(NewCallTargets,
              [](const InstrProfValueData &L, const InstrProfValueData &R) {
-               if (L.Count != R.Count)
-                 return L.Count > R.Count;
-               return L.Value > R.Value;
+               return std::tie(L.Count, L.Value) > std::tie(R.Count, R.Value);
              });
 
   uint32_t MaxMDCount =
diff --git a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
index 0690c21220f89..d6dfb65bf82e6 100644
--- a/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
@@ -69,11 +69,7 @@ getNonRedundantWriteProcRes(const MCSchedClassDesc &SCDesc,
        [](const ResourceMaskAndEntry &A, const ResourceMaskAndEntry &B) {
          unsigned popcntA = popcount(A.first);
          unsigned popcntB = popcount(B.first);
-         if (popcntA < popcntB)
-           return true;
-         if (popcntA > popcntB)
-           return false;
-         return A.first < B.first;
+         return std::tie(popcntA, A.first) < std::tie(popcntB, B.first);
        });
 
   SmallVector<float, 32> ProcResUnitUsage(NumProcRes);

``````````

</details>


https://github.com/llvm/llvm-project/pull/141353


More information about the llvm-commits mailing list