Skip to content

Commit

Permalink
Move dead code removal in lower after last updategraph (#69421)
Browse files Browse the repository at this point in the history
* Move dead code removal in lower after last updategraph

* Add back in non-optimizing
  • Loading branch information
kunalspathak authored May 21, 2022
1 parent 3b2f833 commit c190f6b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4967,7 +4967,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.

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBlock*> worklist(jitstd::allocator<void>(getAllocator(CMK_Reachability)));
worklist.push_back(fgFirstBB);

Expand Down Expand Up @@ -730,6 +732,7 @@ void Compiler::fgRemoveDeadBlocks()
fgVerifyHandlerTab();
fgDebugCheckBBlist(false);
#endif // DEBUG
return changed;
}

//-------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6408,12 +6408,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
Expand Down

0 comments on commit c190f6b

Please sign in to comment.