Skip to content

[llvm] Use std::tie to implement operator< (NFC) #139391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 10, 2025

@llvm/pr-subscribers-backend-hexagon

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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

2 Files Affected:

  • (modified) llvm/include/llvm/Support/InstructionCost.h (+2-3)
  • (modified) llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp (+1-5)
diff --git a/llvm/include/llvm/Support/InstructionCost.h b/llvm/include/llvm/Support/InstructionCost.h
index d5f7457e04748..8e8aa6cfd717b 100644
--- a/llvm/include/llvm/Support/InstructionCost.h
+++ b/llvm/include/llvm/Support/InstructionCost.h
@@ -20,6 +20,7 @@
 
 #include "llvm/Support/MathExtras.h"
 #include <limits>
+#include <tuple>
 
 namespace llvm {
 
@@ -191,9 +192,7 @@ class InstructionCost {
   /// the states are valid and users can test for validity of the cost
   /// explicitly.
   bool operator<(const InstructionCost &RHS) const {
-    if (State != RHS.State)
-      return State < RHS.State;
-    return Value < RHS.Value;
+    return std::tie(State, Value) < std::tie(RHS.State, RHS.Value);
   }
 
   bool operator==(const InstructionCost &RHS) const {
diff --git a/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp b/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
index bc51b293b5dda..f38e7b879e5f0 100644
--- a/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
@@ -107,11 +107,7 @@ namespace {
       return !operator==(R);
     }
     bool operator<(const OffsetRange &R) const {
-      if (Min != R.Min)
-        return Min < R.Min;
-      if (Max != R.Max)
-        return Max < R.Max;
-      return Align < R.Align;
+      return std::tie(Min, Max, Align) < std::tie(R.Min, R.Max, R.Align);
     }
     static OffsetRange zero() { return {0, 0, 1}; }
   };

@kazutakahirata kazutakahirata changed the title [llvm] Use std::tie to Implment operator< (NFC) [llvm] Use std::tie to implment operator< (NFC) May 10, 2025
@kazutakahirata kazutakahirata changed the title [llvm] Use std::tie to implment operator< (NFC) [llvm] Use std::tie to implement operator< (NFC) May 10, 2025
@kazutakahirata kazutakahirata merged commit 6c31984 into llvm:main May 11, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_operator_less_llvm branch May 11, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants