[CINN]:Fix ComparePriority to satisfy strict weak ordering for std::sort by feixi21 · Pull Request #76027 · PaddlePaddle/Paddle

PR Category

CINN

PR Types

Bug fixes

Description

std::sort 要求其比较函数满足严格弱序关系,即对于任意对象 acompare(a, a) 必须返回 false

原始的 ComparePriority 函数返回 bool 类型,难以正确表达相等情形,存在违反该规则的风险。
为此,将 ComparePriority(lhs, rhs) 的返回类型由 bool 修改为 int,语义如下:

  • 返回 -1 表示 lhs < rhs
  • 返回 0 表示 lhs == rhs
  • 返回 1 表示 lhs > rhs

同时引入包装函数 SortComparePriority(lhs, rhs),专用于 std::sort。该函数内部调用 ComparePriority,仅当返回值为 1 时返回 true,其余情况返回 false,从而确保满足严格弱序要求。