From bc0227e9e47896b6e229460e8a3eba36db2bae5c Mon Sep 17 00:00:00 2001 From: Brett Simmers Date: Tue, 23 Apr 2024 13:15:38 -0700 Subject: [PATCH] Remove DCHECK from sort comparison function Summary: Our implementation of `std::sort()` (and other functions that take a `Compare` object) does some sanity checks on the provided predicate, including calling `comp(a, a)` and asserting that it's false. This was tripping a `JIT_DCHECK()` in this comparison function. Remove it from the predicate and do a separate pass to ensure uniqueness after sorting. Reviewed By: alexmalyshev Differential Revision: D56479803 fbshipit-source-id: e877d08d2f51271fd668fe1308e34aa571b1652b --- cinderx/Jit/hir/hir.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cinderx/Jit/hir/hir.cpp b/cinderx/Jit/hir/hir.cpp index c18cb4d7527..1e0fbaf129f 100644 --- a/cinderx/Jit/hir/hir.cpp +++ b/cinderx/Jit/hir/hir.cpp @@ -30,9 +30,19 @@ void DeoptBase::sortLiveRegs() { live_regs_.begin(), live_regs_.end(), [](const RegState& a, const RegState& b) { - JIT_DCHECK(a.reg != b.reg, "Same register should not be live twice"); return a.reg->id() < b.reg->id(); }); + + if (kPyDebug) { + // Check for uniqueness after sorting rather than inside the predicate + // passed to std::sort(), in case sort() performs extra comparisons to + // sanity-check our predicate. + auto it = std::adjacent_find( + live_regs_.begin(), + live_regs_.end(), + [](const RegState& a, const RegState& b) { return a.reg == b.reg; }); + JIT_DCHECK(it == live_regs_.end(), "Register {} is live twice", *it->reg); + } } void Phi::setArgs(const std::unordered_map& args) {