diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index c5bab81ae0731..3ed293826f47e 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -4977,9 +4977,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl fgDebugCheckLinks(compStressCompile(STRESS_REMORPH_TREES, 50)); #endif - // Remove dead blocks - DoPhase(this, PHASE_REMOVE_DEAD_BLOCKS, &Compiler::fgRemoveDeadBlocks); - // Dominator and reachability sets are no longer valid. fgDomsComputed = false; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index d7ebb305c9912..14de86836f30e 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4965,7 +4965,7 @@ class Compiler void fgComputeReachability(); // Perform flow graph node reachability analysis. - void fgRemoveDeadBlocks(); // Identify and remove dead blocks. + bool fgRemoveDeadBlocks(); // Identify and remove dead blocks. BasicBlock* fgIntersectDom(BasicBlock* a, BasicBlock* b); // Intersect two immediate dominator sets. diff --git a/src/coreclr/jit/compphases.h b/src/coreclr/jit/compphases.h index 05ec93a76e34b..3b1907e86fde0 100644 --- a/src/coreclr/jit/compphases.h +++ b/src/coreclr/jit/compphases.h @@ -84,7 +84,6 @@ CompPhaseNameMacro(PHASE_OPTIMIZE_BRANCHES, "Redundant branch opts", CompPhaseNameMacro(PHASE_ASSERTION_PROP_MAIN, "Assertion prop", "AST-PROP", false, -1, false) CompPhaseNameMacro(PHASE_OPT_UPDATE_FLOW_GRAPH, "Update flow graph opt pass", "UPD-FG-O", false, -1, false) CompPhaseNameMacro(PHASE_COMPUTE_EDGE_WEIGHTS2, "Compute edge weights (2, false)","EDG-WGT2", false, -1, false) -CompPhaseNameMacro(PHASE_REMOVE_DEAD_BLOCKS, "Remove dead blocks", "DEAD-BLK", false, -1, false) CompPhaseNameMacro(PHASE_INSERT_GC_POLLS, "Insert GC Polls", "GC-POLLS", false, -1, true) CompPhaseNameMacro(PHASE_DETERMINE_FIRST_COLD_BLOCK, "Determine first cold block", "COLD-BLK", false, -1, true) CompPhaseNameMacro(PHASE_RATIONALIZE, "Rationalize IR", "RAT", false, -1, false) diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index 001bd0130c3ea..a243711cb1c3d 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -649,8 +649,10 @@ void Compiler::fgComputeReachability() // be removed. For Arm32, do not remove BBJ_ALWAYS block of // BBJ_CALLFINALLY/BBJ_ALWAYS pair. // -void Compiler::fgRemoveDeadBlocks() +bool Compiler::fgRemoveDeadBlocks() { + JITDUMP("\n*************** In fgRemoveDeadBlocks()"); + jitstd::list worklist(jitstd::allocator(getAllocator(CMK_Reachability))); worklist.push_back(fgFirstBB); @@ -730,6 +732,7 @@ void Compiler::fgRemoveDeadBlocks() fgVerifyHandlerTab(); fgDebugCheckBBlist(false); #endif // DEBUG + return changed; } //------------------------------------------------------------- diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 8c3450988e3d1..56670dff731ac 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -6393,12 +6393,19 @@ PhaseStatus Lowering::DoPhase() { comp->optLoopsMarked = false; bool modified = comp->fgUpdateFlowGraph(); + modified |= comp->fgRemoveDeadBlocks(); + if (modified) { JITDUMP("had to run another liveness pass:\n"); comp->fgLocalVarLiveness(); } } + else + { + // If we are not optimizing, remove the dead blocks regardless. + comp->fgRemoveDeadBlocks(); + } // Recompute local var ref counts again after liveness to reflect // impact of any dead code removal. Note this may leave us with