Skip to content

Commit 3e798dd

Browse files
committedNov 26, 2021
8275330: C2: assert(n->is_Root() || n->is_Region() || n->is_Phi() || n->is_MachMerge() || def_block->dominates(block)) failed: uses must be dominated by definitions
Reviewed-by: thartmann, chagedorn
1 parent 99e4bda commit 3e798dd

File tree

8 files changed

+168
-55
lines changed

8 files changed

+168
-55
lines changed
 

‎src/hotspot/share/opto/loopPredicate.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ void PhaseIdealLoop::clone_skeleton_predicates_to_unswitched_loop(IdealLoopTree*
341341
assert(predicate->is_Proj() && predicate->as_Proj()->is_IfProj(), "predicate must be a projection of an if node");
342342
IfProjNode* predicate_proj = predicate->as_IfProj();
343343

344-
ProjNode* fast_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, uncommon_proj, reason, iffast_pred, loop);
344+
ProjNode* fast_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, reason, iffast_pred);
345345
assert(skeleton_predicate_has_opaque(fast_proj->in(0)->as_If()), "must find skeleton predicate for fast loop");
346-
ProjNode* slow_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, uncommon_proj, reason, ifslow_pred, loop);
346+
ProjNode* slow_proj = clone_skeleton_predicate_for_unswitched_loops(iff, predicate_proj, reason, ifslow_pred);
347347
assert(skeleton_predicate_has_opaque(slow_proj->in(0)->as_If()), "must find skeleton predicate for slow loop");
348348

349349
// Update control dependent data nodes.
@@ -397,10 +397,10 @@ void PhaseIdealLoop::get_skeleton_predicates(Node* predicate, Unique_Node_List&
397397
// Clone a skeleton predicate for an unswitched loop. OpaqueLoopInit and OpaqueLoopStride nodes are cloned and uncommon
398398
// traps are kept for the predicate (a Halt node is used later when creating pre/main/post loops and copying this cloned
399399
// predicate again).
400-
ProjNode* PhaseIdealLoop::clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate, Node* uncommon_proj,
401-
Deoptimization::DeoptReason reason, ProjNode* output_proj,
402-
IdealLoopTree* loop) {
403-
Node* bol = clone_skeleton_predicate_bool(iff, NULL, NULL, predicate, uncommon_proj, output_proj, loop);
400+
ProjNode* PhaseIdealLoop::clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate,
401+
Deoptimization::DeoptReason reason,
402+
ProjNode* output_proj) {
403+
Node* bol = clone_skeleton_predicate_bool(iff, NULL, NULL, output_proj);
404404
ProjNode* proj = create_new_if_for_predicate(output_proj, NULL, reason, iff->Opcode(), predicate->is_IfTrue());
405405
_igvn.replace_input_of(proj->in(0), 1, bol);
406406
_igvn.replace_input_of(output_proj->in(0), 0, proj);

‎src/hotspot/share/opto/loopTransform.cpp

+50-16
Original file line numberDiff line numberDiff line change
@@ -1287,10 +1287,12 @@ void PhaseIdealLoop::copy_skeleton_predicates_to_main_loop_helper(Node* predicat
12871287
// Clone the skeleton predicate twice and initialize one with the initial
12881288
// value of the loop induction variable. Leave the other predicate
12891289
// to be initialized when increasing the stride during loop unrolling.
1290-
prev_proj = clone_skeleton_predicate_for_main_loop(iff, opaque_init, NULL, predicate, uncommon_proj, current_proj, outer_loop, prev_proj);
1290+
prev_proj = clone_skeleton_predicate_for_main_or_post_loop(iff, opaque_init, NULL, predicate, uncommon_proj,
1291+
current_proj, outer_loop, prev_proj);
12911292
assert(skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "");
12921293

1293-
prev_proj = clone_skeleton_predicate_for_main_loop(iff, init, stride, predicate, uncommon_proj, current_proj, outer_loop, prev_proj);
1294+
prev_proj = clone_skeleton_predicate_for_main_or_post_loop(iff, init, stride, predicate, uncommon_proj,
1295+
current_proj, outer_loop, prev_proj);
12941296
assert(!skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "");
12951297

12961298
// Rewire any control inputs from the cloned skeleton predicates down to the main and post loop for data nodes that are part of the
@@ -1367,8 +1369,7 @@ bool PhaseIdealLoop::skeleton_predicate_has_opaque(IfNode* iff) {
13671369
// Clone the skeleton predicate bool for a main or unswitched loop:
13681370
// Main loop: Set new_init and new_stride nodes as new inputs.
13691371
// Unswitched loop: new_init and new_stride are both NULL. Clone OpaqueLoopInit and OpaqueLoopStride instead.
1370-
Node* PhaseIdealLoop::clone_skeleton_predicate_bool(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj,
1371-
Node* control, IdealLoopTree* outer_loop) {
1372+
Node* PhaseIdealLoop::clone_skeleton_predicate_bool(Node* iff, Node* new_init, Node* new_stride, Node* control) {
13721373
Node_Stack to_clone(2);
13731374
to_clone.push(iff->in(1), 1);
13741375
uint current = C->unique();
@@ -1444,9 +1445,9 @@ Node* PhaseIdealLoop::clone_skeleton_predicate_bool(Node* iff, Node* new_init, N
14441445

14451446
// Clone a skeleton predicate for the main loop. new_init and new_stride are set as new inputs. Since the predicates cannot fail at runtime,
14461447
// Halt nodes are inserted instead of uncommon traps.
1447-
Node* PhaseIdealLoop::clone_skeleton_predicate_for_main_loop(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj,
1448-
Node* control, IdealLoopTree* outer_loop, Node* input_proj) {
1449-
Node* result = clone_skeleton_predicate_bool(iff, new_init, new_stride, predicate, uncommon_proj, control, outer_loop);
1448+
Node* PhaseIdealLoop::clone_skeleton_predicate_for_main_or_post_loop(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj,
1449+
Node* control, IdealLoopTree* outer_loop, Node* input_proj) {
1450+
Node* result = clone_skeleton_predicate_bool(iff, new_init, new_stride, control);
14501451
Node* proj = predicate->clone();
14511452
Node* other_proj = uncommon_proj->clone();
14521453
Node* new_iff = iff->clone();
@@ -1460,8 +1461,8 @@ Node* PhaseIdealLoop::clone_skeleton_predicate_for_main_loop(Node* iff, Node* ne
14601461
C->root()->add_req(halt);
14611462
new_iff->set_req(0, input_proj);
14621463

1463-
register_control(new_iff, outer_loop->_parent, input_proj);
1464-
register_control(proj, outer_loop->_parent, new_iff);
1464+
register_control(new_iff, outer_loop == _ltree_root ? _ltree_root : outer_loop->_parent, input_proj);
1465+
register_control(proj, outer_loop == _ltree_root ? _ltree_root : outer_loop->_parent, new_iff);
14651466
register_control(other_proj, _ltree_root, new_iff);
14661467
register_control(halt, _ltree_root, other_proj);
14671468
return proj;
@@ -1544,7 +1545,8 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
15441545
// Add the post loop
15451546
const uint idx_before_pre_post = Compile::current()->unique();
15461547
CountedLoopNode *post_head = NULL;
1547-
Node *main_exit = insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head);
1548+
Node* post_incr = incr;
1549+
Node* main_exit = insert_post_loop(loop, old_new, main_head, main_end, post_incr, limit, post_head);
15481550
const uint idx_after_post_before_pre = Compile::current()->unique();
15491551

15501552
//------------------------------
@@ -1643,6 +1645,7 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
16431645
assert(post_head->in(1)->is_IfProj(), "must be zero-trip guard If node projection of the post loop");
16441646
copy_skeleton_predicates_to_main_loop(pre_head, castii, stride, outer_loop, outer_main_head, dd_main_head,
16451647
idx_before_pre_post, idx_after_post_before_pre, min_taken, post_head->in(1), old_new);
1648+
copy_skeleton_predicates_to_post_loop(outer_main_head, post_head, post_incr, stride);
16461649

16471650
// Step B4: Shorten the pre-loop to run only 1 iteration (for now).
16481651
// RCE and alignment may change this later.
@@ -1765,6 +1768,7 @@ void PhaseIdealLoop::insert_vector_post_loop(IdealLoopTree *loop, Node_List &old
17651768
// In this case we throw away the result as we are not using it to connect anything else.
17661769
CountedLoopNode *post_head = NULL;
17671770
insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head);
1771+
copy_skeleton_predicates_to_post_loop(main_head->skip_strip_mined(), post_head, incr, main_head->stride());
17681772

17691773
// It's difficult to be precise about the trip-counts
17701774
// for post loops. They are usually very short,
@@ -1811,6 +1815,7 @@ void PhaseIdealLoop::insert_scalar_rced_post_loop(IdealLoopTree *loop, Node_List
18111815
// In this case we throw away the result as we are not using it to connect anything else.
18121816
CountedLoopNode *post_head = NULL;
18131817
insert_post_loop(loop, old_new, main_head, main_end, incr, limit, post_head);
1818+
copy_skeleton_predicates_to_post_loop(main_head->skip_strip_mined(), post_head, incr, main_head->stride());
18141819

18151820
// It's difficult to be precise about the trip-counts
18161821
// for post loops. They are usually very short,
@@ -1827,9 +1832,9 @@ void PhaseIdealLoop::insert_scalar_rced_post_loop(IdealLoopTree *loop, Node_List
18271832

18281833
//------------------------------insert_post_loop-------------------------------
18291834
// Insert post loops. Add a post loop to the given loop passed.
1830-
Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree *loop, Node_List &old_new,
1831-
CountedLoopNode *main_head, CountedLoopEndNode *main_end,
1832-
Node *incr, Node *limit, CountedLoopNode *&post_head) {
1835+
Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree* loop, Node_List& old_new,
1836+
CountedLoopNode* main_head, CountedLoopEndNode* main_end,
1837+
Node*& incr, Node* limit, CountedLoopNode*& post_head) {
18331838
IfNode* outer_main_end = main_end;
18341839
IdealLoopTree* outer_loop = loop;
18351840
if (main_head->is_strip_mined()) {
@@ -1913,8 +1918,8 @@ Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree *loop, Node_List &old_new,
19131918
}
19141919

19151920
// CastII for the new post loop:
1916-
Node* castii = cast_incr_before_loop(zer_opaq->in(1), zer_taken, post_head);
1917-
assert(castii != NULL, "no castII inserted");
1921+
incr = cast_incr_before_loop(zer_opaq->in(1), zer_taken, post_head);
1922+
assert(incr != NULL, "no castII inserted");
19181923

19191924
return new_main_exit;
19201925
}
@@ -1956,7 +1961,8 @@ void PhaseIdealLoop::update_main_loop_skeleton_predicates(Node* ctrl, CountedLoo
19561961
_igvn.replace_input_of(iff, 1, iff->in(1)->in(2));
19571962
} else {
19581963
// Add back predicates updated for the new stride.
1959-
prev_proj = clone_skeleton_predicate_for_main_loop(iff, init, max_value, entry, proj, ctrl, outer_loop, prev_proj);
1964+
prev_proj = clone_skeleton_predicate_for_main_or_post_loop(iff, init, max_value, entry, proj, ctrl, outer_loop,
1965+
prev_proj);
19601966
assert(!skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "unexpected");
19611967
}
19621968
}
@@ -1968,6 +1974,34 @@ void PhaseIdealLoop::update_main_loop_skeleton_predicates(Node* ctrl, CountedLoo
19681974
}
19691975
}
19701976

1977+
void PhaseIdealLoop::copy_skeleton_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head, Node* init, Node* stride) {
1978+
// Go over the skeleton predicates of the main loop and make a copy for the post loop with its initial iv value and
1979+
// stride as inputs.
1980+
Node* post_loop_entry = post_loop_head->in(LoopNode::EntryControl);
1981+
Node* main_loop_entry = main_loop_head->in(LoopNode::EntryControl);
1982+
IdealLoopTree* post_loop = get_loop(post_loop_head);
1983+
1984+
Node* ctrl = main_loop_entry;
1985+
Node* prev_proj = post_loop_entry;
1986+
while (ctrl != NULL && ctrl->is_Proj() && ctrl->in(0)->is_If()) {
1987+
IfNode* iff = ctrl->in(0)->as_If();
1988+
ProjNode* proj = iff->proj_out(1 - ctrl->as_Proj()->_con);
1989+
if (proj->unique_ctrl_out()->Opcode() != Op_Halt) {
1990+
break;
1991+
}
1992+
if (iff->in(1)->Opcode() == Op_Opaque4 && skeleton_predicate_has_opaque(iff)) {
1993+
prev_proj = clone_skeleton_predicate_for_main_or_post_loop(iff, init, stride, ctrl, proj, post_loop_entry,
1994+
post_loop, prev_proj);
1995+
assert(!skeleton_predicate_has_opaque(prev_proj->in(0)->as_If()), "unexpected");
1996+
}
1997+
ctrl = ctrl->in(0)->in(0);
1998+
}
1999+
if (prev_proj != post_loop_entry) {
2000+
_igvn.replace_input_of(post_loop_head, LoopNode::EntryControl, prev_proj);
2001+
set_idom(post_loop_head, prev_proj, dom_depth(post_loop_head));
2002+
}
2003+
}
2004+
19712005
//------------------------------do_unroll--------------------------------------
19722006
// Unroll the loop body one step - make each trip do 2 iterations.
19732007
void PhaseIdealLoop::do_unroll(IdealLoopTree *loop, Node_List &old_new, bool adjust_min_trip) {

‎src/hotspot/share/opto/loopnode.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2389,12 +2389,14 @@ Node* CountedLoopNode::skip_predicates_from_entry(Node* ctrl) {
23892389
}
23902390

23912391
Node* CountedLoopNode::skip_predicates() {
2392+
Node* ctrl = in(LoopNode::EntryControl);
23922393
if (is_main_loop()) {
2393-
Node* ctrl = skip_strip_mined()->in(LoopNode::EntryControl);
2394-
2394+
ctrl = skip_strip_mined()->in(LoopNode::EntryControl);
2395+
}
2396+
if (is_main_loop() || is_post_loop()) {
23952397
return skip_predicates_from_entry(ctrl);
23962398
}
2397-
return in(LoopNode::EntryControl);
2399+
return ctrl;
23982400
}
23992401

24002402

‎src/hotspot/share/opto/loopnode.hpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -917,13 +917,13 @@ class PhaseIdealLoop : public PhaseTransform {
917917
void copy_skeleton_predicates_to_main_loop(CountedLoopNode* pre_head, Node* init, Node* stride, IdealLoopTree* outer_loop, LoopNode* outer_main_head,
918918
uint dd_main_head, const uint idx_before_pre_post, const uint idx_after_post_before_pre,
919919
Node* zero_trip_guard_proj_main, Node* zero_trip_guard_proj_post, const Node_List &old_new);
920-
Node* clone_skeleton_predicate_for_main_loop(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj, Node* control,
921-
IdealLoopTree* outer_loop, Node* input_proj);
922-
Node* clone_skeleton_predicate_bool(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj, Node* control,
923-
IdealLoopTree* outer_loop);
920+
Node* clone_skeleton_predicate_for_main_or_post_loop(Node* iff, Node* new_init, Node* new_stride, Node* predicate, Node* uncommon_proj, Node* control,
921+
IdealLoopTree* outer_loop, Node* input_proj);
922+
Node* clone_skeleton_predicate_bool(Node* iff, Node* new_init, Node* new_stride, Node* control);
924923
static bool skeleton_predicate_has_opaque(IfNode* iff);
925924
static void get_skeleton_predicates(Node* predicate, Unique_Node_List& list, bool get_opaque = false);
926925
void update_main_loop_skeleton_predicates(Node* ctrl, CountedLoopNode* loop_head, Node* init, int stride_con);
926+
void copy_skeleton_predicates_to_post_loop(LoopNode* main_loop_head, CountedLoopNode* post_loop_head, Node* init, Node* stride);
927927
void insert_loop_limit_check(ProjNode* limit_check_proj, Node* cmp_limit, Node* bol);
928928
#ifdef ASSERT
929929
bool only_has_infinite_loops();
@@ -1246,9 +1246,9 @@ class PhaseIdealLoop : public PhaseTransform {
12461246
void insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only );
12471247

12481248
// Add post loop after the given loop.
1249-
Node *insert_post_loop(IdealLoopTree *loop, Node_List &old_new,
1250-
CountedLoopNode *main_head, CountedLoopEndNode *main_end,
1251-
Node *incr, Node *limit, CountedLoopNode *&post_head);
1249+
Node *insert_post_loop(IdealLoopTree* loop, Node_List& old_new,
1250+
CountedLoopNode* main_head, CountedLoopEndNode* main_end,
1251+
Node*& incr, Node* limit, CountedLoopNode*& post_head);
12521252

12531253
// Add an RCE'd post loop which we will multi-version adapt for run time test path usage
12541254
void insert_scalar_rced_post_loop( IdealLoopTree *loop, Node_List &old_new );
@@ -1593,8 +1593,9 @@ class PhaseIdealLoop : public PhaseTransform {
15931593
Node_List* old_new = NULL);
15941594
void clone_skeleton_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, Deoptimization::DeoptReason reason,
15951595
ProjNode* old_predicate_proj, ProjNode* iffast_pred, ProjNode* ifslow_pred);
1596-
ProjNode* clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate, Node* uncommon_proj, Deoptimization::DeoptReason reason,
1597-
ProjNode* output_proj, IdealLoopTree* loop);
1596+
ProjNode* clone_skeleton_predicate_for_unswitched_loops(Node* iff, ProjNode* predicate,
1597+
Deoptimization::DeoptReason reason,
1598+
ProjNode* output_proj);
15981599
static void check_created_predicate_for_unswitching(const Node* new_entry) PRODUCT_RETURN;
15991600

16001601
bool _created_loop_node;

‎src/hotspot/share/opto/macro.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,7 @@ void PhaseMacroExpand::eliminate_macro_nodes() {
23662366
assert(n->Opcode() == Op_LoopLimit ||
23672367
n->Opcode() == Op_Opaque2 ||
23682368
n->Opcode() == Op_Opaque3 ||
2369+
n->Opcode() == Op_Opaque4 ||
23692370
BarrierSet::barrier_set()->barrier_set_c2()->is_gc_barrier_node(n),
23702371
"unknown node type in macro list");
23712372
}
@@ -2427,6 +2428,19 @@ bool PhaseMacroExpand::expand_macro_nodes() {
24272428
_igvn.replace_node(n, repl);
24282429
success = true;
24292430
#endif
2431+
} else if (n->Opcode() == Op_Opaque4) {
2432+
// With Opaque4 nodes, the expectation is that the test of input 1
2433+
// is always equal to the constant value of input 2. So we can
2434+
// remove the Opaque4 and replace it by input 2. In debug builds,
2435+
// leave the non constant test in instead to sanity check that it
2436+
// never fails (if it does, that subgraph was constructed so, at
2437+
// runtime, a Halt node is executed).
2438+
#ifdef ASSERT
2439+
_igvn.replace_node(n, n->in(1));
2440+
#else
2441+
_igvn.replace_node(n, n->in(2));
2442+
#endif
2443+
success = true;
24302444
} else if (n->Opcode() == Op_OuterStripMinedLoop) {
24312445
n->as_OuterStripMinedLoop()->adjust_strip_mined_loop(&_igvn);
24322446
C->remove_macro_node(n);

‎src/hotspot/share/opto/opaquenode.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,6 @@ bool Opaque2Node::cmp( const Node &n ) const {
6060
return (&n == this); // Always fail except on self
6161
}
6262

63-
Node* Opaque4Node::Identity(PhaseGVN* phase) {
64-
if (phase->C->post_loop_opts_phase()) {
65-
// With Opaque4 nodes, the expectation is that the test of input 1
66-
// is always equal to the constant value of input 2. So we can
67-
// remove the Opaque4 and replace it by input 2. In debug builds,
68-
// leave the non constant test in instead to sanity check that it
69-
// never fails (if it does, that subgraph was constructed so, at
70-
// runtime, a Halt node is executed).
71-
#ifdef ASSERT
72-
return this->in(1);
73-
#else
74-
return this->in(2);
75-
#endif
76-
} else {
77-
phase->C->record_for_post_loop_opts_igvn(this);
78-
}
79-
return this;
80-
}
81-
8263
const Type* Opaque4Node::Value(PhaseGVN* phase) const {
8364
return phase->type(in(1));
8465
}

‎src/hotspot/share/opto/opaquenode.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ class Opaque3Node : public Opaque2Node {
114114
// GraphKit::must_be_not_null().
115115
class Opaque4Node : public Node {
116116
public:
117-
Opaque4Node(Compile* C, Node *tst, Node* final_tst) : Node(NULL, tst, final_tst) {}
117+
Opaque4Node(Compile* C, Node *tst, Node* final_tst) : Node(NULL, tst, final_tst) {
118+
init_flags(Flag_is_macro);
119+
C->add_macro_node(this);
120+
}
118121

119122
virtual int Opcode() const;
120123
virtual const Type *bottom_type() const { return TypeInt::BOOL; }
121-
virtual Node* Identity(PhaseGVN* phase);
122124
virtual const Type* Value(PhaseGVN* phase) const;
123125
};
124126

0 commit comments

Comments
 (0)
Failed to load comments.