From dd4af0b65af3537c0f566ebb3a1d837b448d33ee Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Fri, 27 Mar 2026 00:26:52 +0300 Subject: [PATCH] Coalesce adjacent no-GC regions on x86 --- src/coreclr/jit/gcencode.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/gcencode.cpp b/src/coreclr/jit/gcencode.cpp index 24c4c3196a54e4..40908eccefa695 100644 --- a/src/coreclr/jit/gcencode.cpp +++ b/src/coreclr/jit/gcencode.cpp @@ -2124,21 +2124,35 @@ unsigned PendingArgsStack::pasEnumGCoffs(unsigned iter, unsigned* offs) // when reporting interruptible ranges. class NoGCRegionEncoder { - BYTE* dest; + BYTE* dest; + unsigned lastSize = 0; + unsigned lastEndOffs = -1; public: - size_t totalSize; + size_t totalSize = 0; NoGCRegionEncoder(BYTE* dest) : dest(dest) - , totalSize(0) { } // This callback is called for each insGroup marked with IGF_NOGCINTERRUPT. bool operator()(unsigned igFuncIdx, unsigned igOffs, unsigned igSize, unsigned firstInstrSize, bool isInProlog) { - totalSize += encodeUnsigned(dest == NULL ? NULL : dest + totalSize, igOffs); - totalSize += encodeUnsigned(dest == NULL ? NULL : dest + totalSize, igSize); + unsigned size; + if (igOffs == lastEndOffs) // Coalesce adjacent intervals by re-encoding the enlarged size. + { + totalSize -= encodeUnsigned(nullptr, lastSize); + size = lastSize + igSize; + } + else + { + totalSize += encodeUnsigned(dest == nullptr ? nullptr : dest + totalSize, igOffs); + size = igSize; + } + totalSize += encodeUnsigned(dest == nullptr ? nullptr : dest + totalSize, size); + + lastSize = size; + lastEndOffs = igOffs + igSize; return true; } };