From 36657793513070913cc7e95589a712aad3e8228f Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld Date: Fri, 24 Jul 2020 13:19:43 -0700 Subject: [PATCH] Fix GC Poll inlining. (#39881) * Don't inline GC polls in cold basic blocks. * Allow GC poll inlining in basic blocks with `BBF_LOOP_PREHEADER` or `BBF_RETLESS_CALL` set. This fixes one of the assert seen in https://github.com/dotnet/runtime/pull/39474#issuecomment-662033060 Contributes to resolving #39726. --- src/coreclr/src/jit/flowgraph.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/coreclr/src/jit/flowgraph.cpp b/src/coreclr/src/jit/flowgraph.cpp index 65c9af9..f8500bf 100644 --- a/src/coreclr/src/jit/flowgraph.cpp +++ b/src/coreclr/src/jit/flowgraph.cpp @@ -3699,6 +3699,18 @@ PhaseStatus Compiler::fgInsertGCPolls() // We don't want to deal with all the outgoing edges of a switch block. pollType = GCPOLL_CALL; } + else if ((block->bbFlags & BBF_COLD) != 0) + { +#ifdef DEBUG + if (verbose) + { + printf("Selecting CALL poll in block " FMT_BB " because it is a cold block\n", block->bbNum); + } +#endif // DEBUG + + // We don't want to split a cold block. + pollType = GCPOLL_CALL; + } BasicBlock* curBasicBlock = fgCreateGCPoll(pollType, block); createdPollBlocks |= (block != curBasicBlock); @@ -4141,9 +4153,12 @@ BasicBlock* Compiler::fgCreateGCPoll(GCPollType pollType, BasicBlock* block) // We are allowed to split loops and we need to keep a few other flags... // - noway_assert((originalFlags & (BBF_SPLIT_NONEXIST & ~(BBF_LOOP_HEAD | BBF_LOOP_CALL0 | BBF_LOOP_CALL1))) == 0); - top->bbFlags = originalFlags & (~BBF_SPLIT_LOST | BBF_GC_SAFE_POINT); - bottom->bbFlags |= originalFlags & (BBF_SPLIT_GAINED | BBF_IMPORTED | BBF_GC_SAFE_POINT); + noway_assert((originalFlags & (BBF_SPLIT_NONEXIST & + ~(BBF_LOOP_HEAD | BBF_LOOP_CALL0 | BBF_LOOP_CALL1 | BBF_LOOP_PREHEADER | + BBF_RETLESS_CALL))) == 0); + top->bbFlags = originalFlags & (~(BBF_SPLIT_LOST | BBF_LOOP_PREHEADER | BBF_RETLESS_CALL) | BBF_GC_SAFE_POINT); + bottom->bbFlags |= originalFlags & (BBF_SPLIT_GAINED | BBF_IMPORTED | BBF_GC_SAFE_POINT | BBF_LOOP_PREHEADER | + BBF_RETLESS_CALL); bottom->inheritWeight(top); poll->bbFlags |= originalFlags & (BBF_SPLIT_GAINED | BBF_IMPORTED | BBF_GC_SAFE_POINT); -- 2.7.4