Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

std::tie clearly expresses the intent while slightly shortening the
code.

std::tie clearly expresses the intent while slightly shortening the
code.
@llvmbot llvmbot added backend:Hexagon backend:X86 PGO Profile Guided Optimizations labels Jun 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

std::tie clearly expresses the intent while slightly shortening the
code.


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

3 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/SampleProf.h (+2-2)
  • (modified) llvm/lib/Target/Hexagon/HexagonBlockRanges.h (+1-1)
  • (modified) llvm/lib/Target/X86/X86PreTileConfig.cpp (+2-2)
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 09dc7a2944159..4e1f1131b710f 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -289,8 +289,8 @@ struct LineLocation {
   LLVM_ABI void serialize(raw_ostream &OS);
 
   bool operator<(const LineLocation &O) const {
-    return LineOffset < O.LineOffset ||
-           (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
+    return std::tie(LineOffset, Discriminator) <
+           std::tie(O.LineOffset, O.Discriminator);
   }
 
   bool operator==(const LineLocation &O) const {
diff --git a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
index 5a3b6433fba78..e152dbf764c97 100644
--- a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
+++ b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
@@ -37,7 +37,7 @@ struct HexagonBlockRanges {
     unsigned Sub;
 
     bool operator<(RegisterRef R) const {
-      return Reg < R.Reg || (Reg == R.Reg && Sub < R.Sub);
+      return std::tie(Reg, Sub) < std::tie(R.Reg, R.Sub);
     }
   };
   using RegisterSet = std::set<RegisterRef>;
diff --git a/llvm/lib/Target/X86/X86PreTileConfig.cpp b/llvm/lib/Target/X86/X86PreTileConfig.cpp
index f3800d360fdd9..3b4e531f25388 100644
--- a/llvm/lib/Target/X86/X86PreTileConfig.cpp
+++ b/llvm/lib/Target/X86/X86PreTileConfig.cpp
@@ -80,12 +80,12 @@ struct MIRef {
   bool operator<(const MIRef &RHS) const {
     // Comparison between different BBs happens when inserting a MIRef into set.
     // So we compare MBB first to make the insertion happy.
-    return MBB < RHS.MBB || (MBB == RHS.MBB && Pos < RHS.Pos);
+    return std::tie(MBB, Pos) < std::tie(RHS.MBB, RHS.Pos);
   }
   bool operator>(const MIRef &RHS) const {
     // Comparison between different BBs happens when inserting a MIRef into set.
     // So we compare MBB first to make the insertion happy.
-    return MBB > RHS.MBB || (MBB == RHS.MBB && Pos > RHS.Pos);
+    return std::tie(MBB, Pos) > std::tie(RHS.MBB, RHS.Pos);
   }
 };
 

@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-backend-hexagon

Author: Kazu Hirata (kazutakahirata)

Changes

std::tie clearly expresses the intent while slightly shortening the
code.


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

3 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/SampleProf.h (+2-2)
  • (modified) llvm/lib/Target/Hexagon/HexagonBlockRanges.h (+1-1)
  • (modified) llvm/lib/Target/X86/X86PreTileConfig.cpp (+2-2)
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 09dc7a2944159..4e1f1131b710f 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -289,8 +289,8 @@ struct LineLocation {
   LLVM_ABI void serialize(raw_ostream &OS);
 
   bool operator<(const LineLocation &O) const {
-    return LineOffset < O.LineOffset ||
-           (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
+    return std::tie(LineOffset, Discriminator) <
+           std::tie(O.LineOffset, O.Discriminator);
   }
 
   bool operator==(const LineLocation &O) const {
diff --git a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
index 5a3b6433fba78..e152dbf764c97 100644
--- a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
+++ b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
@@ -37,7 +37,7 @@ struct HexagonBlockRanges {
     unsigned Sub;
 
     bool operator<(RegisterRef R) const {
-      return Reg < R.Reg || (Reg == R.Reg && Sub < R.Sub);
+      return std::tie(Reg, Sub) < std::tie(R.Reg, R.Sub);
     }
   };
   using RegisterSet = std::set<RegisterRef>;
diff --git a/llvm/lib/Target/X86/X86PreTileConfig.cpp b/llvm/lib/Target/X86/X86PreTileConfig.cpp
index f3800d360fdd9..3b4e531f25388 100644
--- a/llvm/lib/Target/X86/X86PreTileConfig.cpp
+++ b/llvm/lib/Target/X86/X86PreTileConfig.cpp
@@ -80,12 +80,12 @@ struct MIRef {
   bool operator<(const MIRef &RHS) const {
     // Comparison between different BBs happens when inserting a MIRef into set.
     // So we compare MBB first to make the insertion happy.
-    return MBB < RHS.MBB || (MBB == RHS.MBB && Pos < RHS.Pos);
+    return std::tie(MBB, Pos) < std::tie(RHS.MBB, RHS.Pos);
   }
   bool operator>(const MIRef &RHS) const {
     // Comparison between different BBs happens when inserting a MIRef into set.
     // So we compare MBB first to make the insertion happy.
-    return MBB > RHS.MBB || (MBB == RHS.MBB && Pos > RHS.Pos);
+    return std::tie(MBB, Pos) > std::tie(RHS.MBB, RHS.Pos);
   }
 };
 

@kazutakahirata kazutakahirata merged commit 56da4a9 into llvm:main Jun 28, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250627_operator_less branch June 28, 2025 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:Hexagon backend:X86 PGO Profile Guided Optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants