diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenEnv.cpp @@ -31,20 +31,20 @@ /// Makes target array's elements sorted according to the `order` array. static void sortArrayBasedOnOrder(std::vector &target, ArrayRef order) { - std::sort(target.begin(), target.end(), [&order](LoopId l, LoopId r) { - assert(l != r); - int idxL = -1, idxR = -1; - for (int i = 0, e = order.size(); i < e; i++) { - if (order[i] == l) - idxL = i; - if (order[i] == r) - idxR = i; - } - assert(idxL >= 0 && idxR >= 0); - return idxL < idxR; - }); + std::sort(target.begin(), target.end(), + [&order](const LoopId &l, const LoopId &r) { + assert(std::addressof(l) == std::addressof(r) || l != r); + int idxL = -1, idxR = -1; + for (int i = 0, e = order.size(); i < e; i++) { + if (order[i] == l) + idxL = i; + if (order[i] == r) + idxR = i; + } + assert(idxL >= 0 && idxR >= 0); + return idxL < idxR; + }); } - //===----------------------------------------------------------------------===// // Code generation environment constructor and general methods //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp @@ -566,6 +566,8 @@ continue; return lhsCoords[l].getInt() < rhsCoords[l].getInt(); } + if (std::addressof(lhs) == std::addressof(rhs)) + return false; llvm_unreachable("no equal coordinate in sparse element attr"); });