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

8274328: C2: Redundant CFG edges fixup in block ordering #5705

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 8 additions & 46 deletions src/hotspot/share/opto/block.cpp
Expand Up @@ -905,16 +905,13 @@ void PhaseCFG::fixup_flow() {
// to succs[0], so we want the fall-thru case as the next block in
// succs[1].
if (bnext == bs0) {
// Fall-thru case in succs[0], so flip targets in succs map
// Fall-thru case in succs[0], should be in succs[1], so flip targets in _succs map
Block* tbs0 = block->_succs[0];
Block* tbs1 = block->_succs[1];
block->_succs.map(0, tbs1);
block->_succs.map(1, tbs0);
// Flip projection for each target
ProjNode* tmp = proj0;
proj0 = proj1;
proj1 = tmp;

swap(proj0, proj1);
} else if(bnext != bs1) {
// Need a double-branch
// The existing conditional branch need not change.
Expand Down Expand Up @@ -1648,8 +1645,7 @@ void PhaseBlockLayout::merge_traces(bool fall_thru_only) {
}
}

// Order the sequence of the traces in some desirable way, and fixup the
// jumps at the end of each block.
// Order the sequence of the traces in some desirable way
void PhaseBlockLayout::reorder_traces(int count) {
ResourceArea *area = Thread::current()->resource_area();
Trace ** new_traces = NEW_ARENA_ARRAY(area, Trace *, count);
Expand All @@ -1671,12 +1667,15 @@ void PhaseBlockLayout::reorder_traces(int count) {
// Sort the new trace list by frequency
qsort(new_traces + 1, new_count - 1, sizeof(new_traces[0]), trace_frequency_order);

// Patch up the successor blocks
// Collect all blocks from existing Traces
_cfg.clear_blocks();
for (int i = 0; i < new_count; i++) {
Trace *tr = new_traces[i];
if (tr != NULL) {
tr->fixup_blocks(_cfg);
// push blocks onto the CFG list
for (Block* b = tr->first_block(); b != NULL; b = tr->next(b)) {
_cfg.add_block(b);
}
}
}
}
Expand Down Expand Up @@ -1782,40 +1781,3 @@ bool Trace::backedge(CFGEdge *e) {

return loop_rotated;
}

// push blocks onto the CFG list
// ensure that blocks have the correct two-way branch sense
void Trace::fixup_blocks(PhaseCFG &cfg) {
Block *last = last_block();
for (Block *b = first_block(); b != NULL; b = next(b)) {
cfg.add_block(b);
if (!b->is_connector()) {
int nfallthru = b->num_fall_throughs();
if (b != last) {
if (nfallthru == 2) {
// Ensure that the sense of the branch is correct
Block *bnext = next(b);
Block *bs0 = b->non_connector_successor(0);

MachNode *iff = b->get_node(b->number_of_nodes() - 3)->as_Mach();
ProjNode *proj0 = b->get_node(b->number_of_nodes() - 2)->as_Proj();
ProjNode *proj1 = b->get_node(b->number_of_nodes() - 1)->as_Proj();

if (bnext == bs0) {
// Fall-thru case in succs[0], should be in succs[1]

// Flip targets in _succs map
Block *tbs0 = b->_succs[0];
Block *tbs1 = b->_succs[1];
b->_succs.map( 0, tbs1 );
b->_succs.map( 1, tbs0 );

// Flip projections to match targets
b->map_node(proj1, b->number_of_nodes() - 2);
b->map_node(proj0, b->number_of_nodes() - 1);
}
}
}
}
}
}
7 changes: 3 additions & 4 deletions src/hotspot/share/opto/block.hpp
Expand Up @@ -797,8 +797,6 @@ class Trace : public ResourceObj {
Block * _first; // First block in the trace
Block * _last; // Last block in the trace

// Return the block that follows "b" in the trace.
Block * next(Block *b) const { return _next_list[b->_pre_order]; }
void set_next(Block *b, Block *n) const { _next_list[b->_pre_order] = n; }

// Return the block that precedes "b" in the trace.
Expand Down Expand Up @@ -836,6 +834,9 @@ class Trace : public ResourceObj {
// Return the last block in the trace
Block * last_block() const { return _last; }

// Return the block that follows "b" in the trace.
Block * next(Block *b) const { return _next_list[b->_pre_order]; }

// Insert a trace in the middle of this one after b
void insert_after(Block *b, Trace *tr) {
set_next(tr->last_block(), next(b));
Expand Down Expand Up @@ -869,8 +870,6 @@ class Trace : public ResourceObj {
_last = b;
}

// Adjust the the blocks in this trace
void fixup_blocks(PhaseCFG &cfg);
bool backedge(CFGEdge *e);

#ifndef PRODUCT
Expand Down