diff --git a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp --- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp @@ -260,8 +260,18 @@ #endif } +#ifndef NDEBUG +template +static const char *stringify(T &t, std::string &S) { + raw_string_ostream OS(S); + OS << t; + return OS.str().c_str(); +} +#endif + Error GISelCSEInfo::verify() { #ifndef NDEBUG + std::string S1, S2; handleRecordedInsts(); // For each instruction in map from MI -> UMI, // Profile(MI) and make sure UMI is found for that profile. @@ -274,7 +284,8 @@ if (FoundNode != It.second) return createStringError(std::errc::not_supported, "CSEMap mismatch, InstrMapping has MIs without " - "corresponding Nodes in CSEMap"); + "corresponding Nodes in CSEMap:\n%s", + stringify(*It.second->MI, S1)); } // For every node in the CSEMap, make sure that the InstrMapping @@ -282,11 +293,14 @@ for (const UniqueMachineInstr &UMI : CSEMap) { if (!InstrMapping.count(UMI.MI)) return createStringError(std::errc::not_supported, - "Node in CSE without InstrMapping", UMI.MI); + "Node in CSE without InstrMapping:\n%s", + stringify(*UMI.MI, S1)); if (InstrMapping[UMI.MI] != &UMI) return createStringError(std::make_error_code(std::errc::not_supported), - "Mismatch in CSE mapping"); + "Mismatch in CSE mapping:\n%s\n%s", + stringify(*InstrMapping[UMI.MI]->MI, S1), + stringify(*UMI.MI, S2)); } #endif return Error::success(); diff --git a/llvm/lib/CodeGen/GlobalISel/Combiner.cpp b/llvm/lib/CodeGen/GlobalISel/Combiner.cpp --- a/llvm/lib/CodeGen/GlobalISel/Combiner.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Combiner.cpp @@ -153,8 +153,14 @@ MFChanged |= Changed; } while (Changed); - assert(!CSEInfo || (!errorToBool(CSEInfo->verify()) && - "CSEInfo is not consistent. Likely missing calls to " - "observer on mutations")); +#ifndef NDEBUG + if (CSEInfo) { + if (auto E = CSEInfo->verify()) { + errs() << E << '\n'; + assert(false && "CSEInfo is not consistent. Likely missing calls to " + "observer on mutations."); + } + } +#endif return MFChanged; }