From c57260b685d3a0ed16bece92e5410975fb821d37 Mon Sep 17 00:00:00 2001 From: Andrew Adams Date: Thu, 16 Jul 2026 11:11:41 -0700 Subject: [PATCH 1/2] Use std::tie for lexicographic comparisons in operator< overloads Replace verbose if/else comparison ladders with std::tie in four multi-field operator< overloads: StageStridedLoads::Key, FusedPair, RegionsRequiredQuery, and AssociativeOpsTable's TableKey. Co-Authored-By: Claude Opus 4.8 --- src/AssociativeOpsTable.cpp | 14 ++------- src/Schedule.h | 17 +++-------- src/StageStridedLoads.cpp | 30 +++++-------------- .../mullapudi2016/AutoSchedule.cpp | 19 ++---------- 4 files changed, 18 insertions(+), 62 deletions(-) diff --git a/src/AssociativeOpsTable.cpp b/src/AssociativeOpsTable.cpp index 63b4add503e9..34fb40d93ab5 100644 --- a/src/AssociativeOpsTable.cpp +++ b/src/AssociativeOpsTable.cpp @@ -2,6 +2,7 @@ #include "IRPrinter.h" #include +#include namespace Halide { namespace Internal { @@ -93,17 +94,8 @@ struct TableKey { return (types == other.types) && (root == other.root) && (dim == other.dim); } bool operator<(const TableKey &other) const { - if (types < other.types) { - return true; - } else if (types > other.types) { - return false; - } - if (root < other.root) { - return true; - } else if (root > other.root) { - return false; - } - return (dim < other.dim); + return std::tie(types, root, dim) < + std::tie(other.types, other.root, other.dim); } }; diff --git a/src/Schedule.h b/src/Schedule.h index a72c52bbd59f..fe7eb70b23d2 100644 --- a/src/Schedule.h +++ b/src/Schedule.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -552,19 +553,9 @@ struct FusedPair { (var_name == other.var_name); } bool operator<(const FusedPair &other) const { - if (func_1 != other.func_1) { - return func_1 < other.func_1; - } - if (func_2 != other.func_2) { - return func_2 < other.func_2; - } - if (var_name != other.var_name) { - return var_name < other.var_name; - } - if (stage_1 != other.stage_1) { - return stage_1 < other.stage_1; - } - return stage_2 < other.stage_2; + return std::tie(func_1, func_2, var_name, stage_1, stage_2) < + std::tie(other.func_1, other.func_2, other.var_name, + other.stage_1, other.stage_2); } }; diff --git a/src/StageStridedLoads.cpp b/src/StageStridedLoads.cpp index 896a33b5193e..86efb233c1ad 100644 --- a/src/StageStridedLoads.cpp +++ b/src/StageStridedLoads.cpp @@ -1,3 +1,5 @@ +#include + #include "StageStridedLoads.h" #include "CSE.h" #include "ExprUsesVar.h" @@ -39,31 +41,15 @@ class FindStridedLoads : public IRVisitor { bool operator<(const Key &other) const { // Check fields in order of cost to compare - if (stride < other.stride) { - return true; - } else if (stride > other.stride) { - return false; - } else if (lanes < other.lanes) { - return true; - } else if (lanes > other.lanes) { - return false; - } else if (scope < other.scope) { - return true; - } else if (scope > other.scope) { - return false; - } else if (allocation < other.allocation) { - return true; - } else if (allocation > other.allocation) { - return false; - } else if (type < other.type) { - return true; - } else if (other.type < type) { - return false; - } else if (buf < other.buf) { + auto lhs = std::tie(stride, lanes, scope, allocation, type, buf); + auto rhs = std::tie(other.stride, other.lanes, other.scope, + other.allocation, other.type, other.buf); + if (lhs < rhs) { return true; - } else if (buf > other.buf) { + } else if (rhs < lhs) { return false; } else { + // base compares by graph equivalence, so it can't go in the tuple. return graph_less_than(base, other.base); } } diff --git a/src/autoschedulers/mullapudi2016/AutoSchedule.cpp b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp index 9005999bf1a8..fa98b49e19ee 100644 --- a/src/autoschedulers/mullapudi2016/AutoSchedule.cpp +++ b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace Halide { @@ -203,22 +204,8 @@ struct DependenceAnalysis { (only_regions_computed == other.only_regions_computed); } bool operator<(const RegionsRequiredQuery &other) const { - if (f < other.f) { - return true; - } else if (f > other.f) { - return false; - } - if (stage < other.stage) { - return true; - } else if (stage > other.stage) { - return false; - } - if (only_regions_computed < other.only_regions_computed) { - return true; - } else if (only_regions_computed > other.only_regions_computed) { - return false; - } - return prods < other.prods; + return std::tie(f, stage, only_regions_computed, prods) < + std::tie(other.f, other.stage, other.only_regions_computed, other.prods); } }; struct RegionsRequired { From b7b4e10a828879238330132362683536e6a12678 Mon Sep 17 00:00:00 2001 From: "halide-ci[bot]" <266445882+halide-ci[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 18:19:20 +0000 Subject: [PATCH 2/2] Apply pre-commit auto-fixes --- src/StageStridedLoads.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StageStridedLoads.cpp b/src/StageStridedLoads.cpp index 86efb233c1ad..2912bbd2c726 100644 --- a/src/StageStridedLoads.cpp +++ b/src/StageStridedLoads.cpp @@ -1,6 +1,5 @@ #include -#include "StageStridedLoads.h" #include "CSE.h" #include "ExprUsesVar.h" #include "IREquality.h" @@ -9,6 +8,7 @@ #include "IRVisitor.h" #include "Scope.h" #include "Simplify.h" +#include "StageStridedLoads.h" #include "Substitute.h" namespace Halide {