@@ -4128,6 +4128,45 @@ void PhaseIdealLoop::eliminate_useless_predicates() {
4128
4128
}
4129
4129
}
4130
4130
4131
+ // If a post or main loop is removed due to an assert predicate, the opaque that guards the loop is not needed anymore
4132
+ void PhaseIdealLoop::eliminate_useless_zero_trip_guard () {
4133
+ if (_zero_trip_guard_opaque_nodes.size () == 0 ) {
4134
+ return ;
4135
+ }
4136
+ Unique_Node_List useful_zero_trip_guard_opaques_nodes;
4137
+ for (LoopTreeIterator iter (_ltree_root); !iter.done (); iter.next ()) {
4138
+ IdealLoopTree* lpt = iter.current ();
4139
+ if (lpt->_child == nullptr && lpt->is_counted ()) {
4140
+ CountedLoopNode* head = lpt->_head ->as_CountedLoop ();
4141
+ Node* opaque = head->is_canonical_loop_entry ();
4142
+ if (opaque != nullptr ) {
4143
+ useful_zero_trip_guard_opaques_nodes.push (opaque);
4144
+ }
4145
+ }
4146
+ }
4147
+ for (uint i = 0 ; i < _zero_trip_guard_opaque_nodes.size (); ++i) {
4148
+ OpaqueZeroTripGuardNode* opaque = ((OpaqueZeroTripGuardNode*)_zero_trip_guard_opaque_nodes.at (i));
4149
+ DEBUG_ONLY (CountedLoopNode* guarded_loop = opaque->guarded_loop ());
4150
+ if (!useful_zero_trip_guard_opaques_nodes.member (opaque)) {
4151
+ IfNode* iff = opaque->if_node ();
4152
+ IdealLoopTree* loop = get_loop (iff);
4153
+ while (loop != _ltree_root && loop != nullptr ) {
4154
+ loop = loop->_parent ;
4155
+ }
4156
+ if (loop == nullptr ) {
4157
+ // unreachable from _ltree_root: zero trip guard is in a newly discovered infinite loop.
4158
+ // We can't tell if the opaque node is useful or not
4159
+ assert (guarded_loop == nullptr || guarded_loop->is_in_infinite_subgraph (), " " );
4160
+ } else {
4161
+ assert (guarded_loop == nullptr , " " );
4162
+ this ->_igvn .replace_node (opaque, opaque->in (1 ));
4163
+ }
4164
+ } else {
4165
+ assert (guarded_loop != nullptr , " " );
4166
+ }
4167
+ }
4168
+ }
4169
+
4131
4170
// ------------------------process_expensive_nodes-----------------------------
4132
4171
// Expensive nodes have their control input set to prevent the GVN
4133
4172
// from commoning them and as a result forcing the resulting node to
@@ -4416,6 +4455,8 @@ void PhaseIdealLoop::build_and_optimize() {
4416
4455
_igvn.remove_globally_dead_node (_deadlist.pop ());
4417
4456
}
4418
4457
4458
+ eliminate_useless_zero_trip_guard ();
4459
+
4419
4460
if (stop_early) {
4420
4461
assert (do_expensive_nodes, " why are we here?" );
4421
4462
if (process_expensive_nodes ()) {
@@ -6144,6 +6185,11 @@ void PhaseIdealLoop::build_loop_late_post_work(Node *n, bool pinned) {
6144
6185
IdealLoopTree *chosen_loop = get_loop (least);
6145
6186
if ( !chosen_loop->_child ) // Inner loop?
6146
6187
chosen_loop->_body .push (n);// Collect inner loops
6188
+
6189
+ if (!_verify_only && n->Opcode () == Op_OpaqueZeroTripGuard) {
6190
+ _zero_trip_guard_opaque_nodes.push (n);
6191
+ }
6192
+
6147
6193
}
6148
6194
6149
6195
#ifdef ASSERT
0 commit comments