Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move dead code removal in lower after last updategraph #69421

Merged
merged 2 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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.

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 @@ -6393,12 +6393,19 @@ PhaseStatus Lowering::DoPhase()
{
comp->optLoopsMarked = false;
bool modified = comp->fgUpdateFlowGraph();
modified |= comp->fgRemoveDeadBlocks();
Copy link
Member

@jakobbotsch jakobbotsch May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fgUpdateFlowGraph returned false, do we need to run this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This should be run regardless (as we do today). I want to do it after update flow graph because it might make more blocks eligible for removing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.


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