@@ -99,40 +99,38 @@ void PhaseIdealLoop::register_control(Node* n, IdealLoopTree *loop, Node* pred,
99
99
// We will create a region to guard the uct call if there is no one there.
100
100
// The continuation projection (if_cont) of the new_iff is returned which
101
101
// is an IfTrue projection. This code is also used to clone predicates to cloned loops.
102
- IfProjNode * PhaseIdealLoop::create_new_if_for_predicate (ParsePredicateSuccessProj* parse_predicate_proj, Node* new_entry ,
103
- Deoptimization::DeoptReason reason,
102
+ IfTrueNode * PhaseIdealLoop::create_new_if_for_predicate (ParsePredicateSuccessProj* parse_predicate_success_proj ,
103
+ Node* new_entry, const Deoptimization::DeoptReason reason,
104
104
const int opcode, const bool rewire_uncommon_proj_phi_inputs) {
105
- assert (parse_predicate_proj->is_uncommon_trap_if_pattern (reason), " must be a uct if pattern!" );
106
- ParsePredicateNode* parse_predicate = parse_predicate_proj->in (0 )->as_ParsePredicate ();
107
-
108
- ProjNode* uncommon_proj = parse_predicate->proj_out (false );
109
- Node* uct_region = uncommon_proj->unique_ctrl_out ();
110
- assert (uct_region->is_Region () || uct_region->is_Call (), " must be a region or call uct" );
105
+ assert (parse_predicate_success_proj->is_uncommon_trap_if_pattern (reason), " must be a uct if pattern!" );
106
+ ParsePredicateNode* parse_predicate = parse_predicate_success_proj->in (0 )->as_ParsePredicate ();
107
+ ParsePredicateUncommonProj* uncommon_proj = parse_predicate->uncommon_proj ();
108
+ Node* uncommon_trap = parse_predicate->uncommon_trap ();
111
109
112
110
uint proj_index = 1 ; // region's edge corresponding to uncommon_proj
113
- if (!uct_region ->is_Region ()) { // create a region to guard the call
114
- assert (uct_region ->is_Call (), " must be call uct" );
115
- CallNode* call = uct_region ->as_Call ();
111
+ if (!uncommon_trap ->is_Region ()) { // create a region to guard the call
112
+ assert (uncommon_trap ->is_Call (), " must be call uct" );
113
+ CallNode* call = uncommon_trap ->as_Call ();
116
114
IdealLoopTree* loop = get_loop (call);
117
- uct_region = new RegionNode (1 );
115
+ uncommon_trap = new RegionNode (1 );
118
116
Node* uncommon_proj_orig = uncommon_proj;
119
- uncommon_proj = uncommon_proj->clone ()->as_Proj ();
117
+ uncommon_proj = uncommon_proj->clone ()->as_IfFalse ();
120
118
register_control (uncommon_proj, loop, parse_predicate);
121
- uct_region ->add_req (uncommon_proj);
122
- register_control (uct_region , loop, uncommon_proj);
123
- _igvn.replace_input_of (call, 0 , uct_region );
119
+ uncommon_trap ->add_req (uncommon_proj);
120
+ register_control (uncommon_trap , loop, uncommon_proj);
121
+ _igvn.replace_input_of (call, 0 , uncommon_trap );
124
122
// When called from beautify_loops() idom is not constructed yet.
125
123
if (_idom != nullptr ) {
126
- set_idom (call, uct_region , dom_depth (uct_region ));
124
+ set_idom (call, uncommon_trap , dom_depth (uncommon_trap ));
127
125
}
128
126
// Move nodes pinned on the projection or whose control is set to
129
127
// the projection to the region.
130
- lazy_replace (uncommon_proj_orig, uct_region );
128
+ lazy_replace (uncommon_proj_orig, uncommon_trap );
131
129
} else {
132
130
// Find region's edge corresponding to uncommon_proj
133
- for (; proj_index < uct_region ->req (); proj_index++)
134
- if (uct_region ->in (proj_index) == uncommon_proj) break ;
135
- assert (proj_index < uct_region ->req (), " sanity" );
131
+ for (; proj_index < uncommon_trap ->req (); proj_index++)
132
+ if (uncommon_trap ->in (proj_index) == uncommon_proj) break ;
133
+ assert (proj_index < uncommon_trap ->req (), " sanity" );
136
134
}
137
135
138
136
Node* entry = parse_predicate->in (0 );
@@ -157,22 +155,23 @@ IfProjNode* PhaseIdealLoop::create_new_if_for_predicate(ParsePredicateSuccessPro
157
155
fatal (" no other If variant here" );
158
156
}
159
157
register_control (new_iff, lp, entry);
160
- IfProjNode* if_cont = new IfTrueNode (new_iff);
161
- IfProjNode* if_uct = new IfFalseNode (new_iff);
158
+
159
+ IfTrueNode* if_cont = new IfTrueNode (new_iff);
160
+ IfFalseNode* if_uct = new IfFalseNode (new_iff);
162
161
163
162
register_control (if_cont, lp, new_iff);
164
- register_control (if_uct, get_loop (uct_region ), new_iff);
163
+ register_control (if_uct, get_loop (uncommon_trap ), new_iff);
165
164
166
- _igvn.add_input_to (uct_region , if_uct);
165
+ _igvn.add_input_to (uncommon_trap , if_uct);
167
166
168
167
// If rgn has phis add new edges which has the same
169
168
// value as on original uncommon_proj pass.
170
- assert (uct_region ->in (uct_region ->req () - 1 ) == if_uct, " new edge should be last" );
169
+ assert (uncommon_trap ->in (uncommon_trap ->req () - 1 ) == if_uct, " new edge should be last" );
171
170
bool has_phi = false ;
172
- for (DUIterator_Fast imax, i = uct_region ->fast_outs (imax); i < imax; i++) {
173
- Node* use = uct_region ->fast_out (i);
171
+ for (DUIterator_Fast imax, i = uncommon_trap ->fast_outs (imax); i < imax; i++) {
172
+ Node* use = uncommon_trap ->fast_out (i);
174
173
if (use->is_Phi () && use->outcnt () > 0 ) {
175
- assert (use->in (0 ) == uct_region , " " );
174
+ assert (use->in (0 ) == uncommon_trap , " " );
176
175
_igvn.rehash_node_delayed (use);
177
176
Node* phi_input = use->in (proj_index);
178
177
@@ -193,7 +192,7 @@ IfProjNode* PhaseIdealLoop::create_new_if_for_predicate(ParsePredicateSuccessPro
193
192
has_phi = true ;
194
193
}
195
194
}
196
- assert (!has_phi || uct_region ->req () > 3 , " no phis when region is created" );
195
+ assert (!has_phi || uncommon_trap ->req () > 3 , " no phis when region is created" );
197
196
198
197
if (new_entry == nullptr ) {
199
198
// Attach if_cont to iff
@@ -205,12 +204,12 @@ IfProjNode* PhaseIdealLoop::create_new_if_for_predicate(ParsePredicateSuccessPro
205
204
206
205
// When called from beautify_loops() idom is not constructed yet.
207
206
if (_idom != nullptr ) {
208
- Node* ridom = idom (uct_region );
207
+ Node* ridom = idom (uncommon_trap );
209
208
Node* nrdom = dom_lca_internal (ridom, new_iff);
210
- set_idom (uct_region , nrdom, dom_depth (uct_region ));
209
+ set_idom (uncommon_trap , nrdom, dom_depth (uncommon_trap ));
211
210
}
212
211
213
- return if_cont-> as_IfProj () ;
212
+ return if_cont;
214
213
}
215
214
216
215
// Update ctrl and control inputs of all data nodes starting from 'node' to 'new_ctrl' which have 'old_ctrl' as
@@ -757,8 +756,8 @@ bool IdealLoopTree::is_range_check_if(IfProjNode* if_success_proj, PhaseIdealLoo
757
756
// max(scale*i + offset) = scale*(limit-stride) + offset
758
757
// (2) stride*scale < 0
759
758
// max(scale*i + offset) = scale*init + offset
760
- BoolNode* PhaseIdealLoop::rc_predicate (IdealLoopTree* loop, Node* ctrl, int scale, Node* offset, Node* init,
761
- Node* limit, jint stride, Node* range, bool upper, bool & overflow) {
759
+ BoolNode* PhaseIdealLoop::rc_predicate (Node* ctrl, const int scale, Node* offset, Node* init, Node* limit ,
760
+ const jint stride, Node* range, const bool upper, bool & overflow) {
762
761
jint con_limit = (limit != nullptr && limit->is_Con ()) ? limit->get_int () : 0 ;
763
762
jint con_init = init->is_Con () ? init->get_int () : 0 ;
764
763
jint con_offset = offset->is_Con () ? offset->get_int () : 0 ;
@@ -1165,18 +1164,19 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
1165
1164
reason,
1166
1165
iff->Opcode ());
1167
1166
Node* ctrl = new_predicate_proj->in (0 )->as_If ()->in (0 );
1168
- BoolNode* new_predicate_bol = invar.clone (bol, ctrl)->as_Bool ();
1167
+ BoolNode* hoisted_check_predicate_bool = invar.clone (bol, ctrl)->as_Bool ();
1169
1168
1170
1169
// Negate test if necessary (Parse Predicates always have IfTrue as success projection and IfFalse as uncommon trap)
1171
1170
bool negated = false ;
1172
1171
if (if_success_proj->is_IfFalse ()) {
1173
- new_predicate_bol = new BoolNode (new_predicate_bol->in (1 ), new_predicate_bol->_test .negate ());
1174
- register_new_node (new_predicate_bol, ctrl);
1172
+ hoisted_check_predicate_bool = new BoolNode (hoisted_check_predicate_bool->in (1 ),
1173
+ hoisted_check_predicate_bool->_test .negate ());
1174
+ register_new_node (hoisted_check_predicate_bool, ctrl);
1175
1175
negated = true ;
1176
1176
}
1177
1177
IfNode* new_predicate_iff = new_predicate_proj->in (0 )->as_If ();
1178
1178
_igvn.hash_delete (new_predicate_iff);
1179
- new_predicate_iff->set_req (1 , new_predicate_bol );
1179
+ new_predicate_iff->set_req (1 , hoisted_check_predicate_bool );
1180
1180
1181
1181
C->print_method (PHASE_AFTER_LOOP_PREDICATION_IC, 4 , new_predicate_proj->in (0 ));
1182
1182
@@ -1220,7 +1220,8 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
1220
1220
1221
1221
// Perform cloning to keep Invariance state correct since the
1222
1222
// late schedule will place invariant things in the loop.
1223
- Node* ctrl = parse_predicate_proj->in (0 )->as_If ()->in (0 );
1223
+ ParsePredicateNode* parse_predicate = parse_predicate_proj->in (0 )->as_ParsePredicate ();
1224
+ Node* ctrl = parse_predicate->in (0 );
1224
1225
rng = invar.clone (rng, ctrl);
1225
1226
if (offset && offset != zero) {
1226
1227
assert (invar.is_invariant (offset), " offset must be loop invariant" );
@@ -1229,25 +1230,28 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
1229
1230
// If predicate expressions may overflow in the integer range, longs are used.
1230
1231
bool overflow = false ;
1231
1232
// Test the lower bound
1232
- BoolNode* lower_bound_bol = rc_predicate (loop, ctrl, scale, offset, init, limit, stride, rng, false , overflow);
1233
+ BoolNode* lower_bound_bol = rc_predicate (ctrl, scale, offset, init, limit, stride, rng, false , overflow);
1233
1234
1234
1235
const int if_opcode = iff->Opcode ();
1235
1236
IfProjNode* lower_bound_proj = create_new_if_for_predicate (parse_predicate_proj, nullptr , reason, overflow ? Op_If : if_opcode);
1236
1237
IfNode* lower_bound_iff = lower_bound_proj->in (0 )->as_If ();
1237
1238
_igvn.hash_delete (lower_bound_iff);
1238
1239
lower_bound_iff->set_req (1 , lower_bound_bol);
1239
- if (TraceLoopPredicate) tty->print_cr (" lower bound check if: %d" , lower_bound_iff->_idx );
1240
+ if (TraceLoopPredicate) {
1241
+ tty->print_cr (" lower bound check if: %d" , lower_bound_iff->_idx );
1242
+ }
1240
1243
1241
1244
// Test the upper bound
1242
- BoolNode* upper_bound_bol = rc_predicate (loop, lower_bound_proj, scale, offset, init, limit, stride, rng, true ,
1243
- overflow);
1245
+ BoolNode* upper_bound_bol = rc_predicate (lower_bound_proj, scale, offset, init, limit, stride, rng, true , overflow);
1244
1246
1245
1247
IfProjNode* upper_bound_proj = create_new_if_for_predicate (parse_predicate_proj, nullptr , reason, overflow ? Op_If : if_opcode);
1246
1248
assert (upper_bound_proj->in (0 )->as_If ()->in (0 ) == lower_bound_proj, " should dominate" );
1247
1249
IfNode* upper_bound_iff = upper_bound_proj->in (0 )->as_If ();
1248
1250
_igvn.hash_delete (upper_bound_iff);
1249
1251
upper_bound_iff->set_req (1 , upper_bound_bol);
1250
- if (TraceLoopPredicate) tty->print_cr (" upper bound check if: %d" , upper_bound_iff->_idx );
1252
+ if (TraceLoopPredicate) {
1253
+ tty->print_cr (" upper bound check if: %d" , upper_bound_iff->_idx );
1254
+ }
1251
1255
1252
1256
// Fall through into rest of the cleanup code which will move any dependent nodes to the skeleton predicates of the
1253
1257
// upper bound test. We always need to create skeleton predicates in order to properly remove dead loops when later
@@ -1294,7 +1298,7 @@ IfProjNode* PhaseIdealLoop::add_template_assertion_predicate(IfNode* iff, IdealL
1294
1298
Node* opaque_init = new OpaqueLoopInitNode (C, init);
1295
1299
register_new_node (opaque_init, upper_bound_proj);
1296
1300
bool negate = (if_proj->_con != parse_predicate_proj->_con );
1297
- BoolNode* bol = rc_predicate (loop, upper_bound_proj, scale, offset, opaque_init, limit, stride, rng,
1301
+ BoolNode* bol = rc_predicate (upper_bound_proj, scale, offset, opaque_init, limit, stride, rng,
1298
1302
(stride > 0 ) != (scale > 0 ), overflow);
1299
1303
Node* opaque_bol = new Opaque4Node (C, bol, _igvn.intcon (1 )); // This will go away once loop opts are over
1300
1304
C->add_template_assertion_predicate_opaq (opaque_bol);
@@ -1317,7 +1321,7 @@ IfProjNode* PhaseIdealLoop::add_template_assertion_predicate(IfNode* iff, IdealL
1317
1321
max_value = new CastIINode (max_value, loop->_head ->as_CountedLoop ()->phi ()->bottom_type ());
1318
1322
register_new_node (max_value, parse_predicate_proj);
1319
1323
1320
- bol = rc_predicate (loop, new_proj, scale, offset, max_value, limit, stride, rng, (stride > 0 ) != (scale > 0 ),
1324
+ bol = rc_predicate (new_proj, scale, offset, max_value, limit, stride, rng, (stride > 0 ) != (scale > 0 ),
1321
1325
overflow);
1322
1326
opaque_bol = new Opaque4Node (C, bol, _igvn.intcon (1 ));
1323
1327
C->add_template_assertion_predicate_opaq (opaque_bol);
@@ -1340,10 +1344,6 @@ bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree* loop) {
1340
1344
return false ;
1341
1345
}
1342
1346
1343
- if (head->is_OuterStripMinedLoop ()) {
1344
- return false ;
1345
- }
1346
-
1347
1347
CountedLoopNode *cl = nullptr ;
1348
1348
if (head->is_valid_counted_loop (T_INT)) {
1349
1349
cl = head->as_CountedLoop ();
@@ -1514,25 +1514,30 @@ bool PhaseIdealLoop::can_create_loop_predicates(const PredicateBlock* profiled_l
1514
1514
1515
1515
// ------------------------------loop_predication--------------------------------
1516
1516
// driver routine for loop predication optimization
1517
- bool IdealLoopTree::loop_predication ( PhaseIdealLoop * phase) {
1517
+ bool IdealLoopTree::loop_predication (PhaseIdealLoop* phase) {
1518
1518
bool hoisted = false ;
1519
1519
// Recursively promote predicates
1520
1520
if (_child) {
1521
1521
hoisted = _child->loop_predication ( phase);
1522
1522
}
1523
1523
1524
- // self
1524
+ // Self
1525
1525
if (can_apply_loop_predication ()) {
1526
1526
hoisted |= phase->loop_predication_impl (this );
1527
1527
}
1528
1528
1529
- if (_next) { // sibling
1529
+ // Sibling
1530
+ if (_next) {
1530
1531
hoisted |= _next->loop_predication ( phase);
1531
1532
}
1532
1533
1533
1534
return hoisted;
1534
1535
}
1535
1536
1536
1537
bool IdealLoopTree::can_apply_loop_predication () {
1537
- return _head->is_Loop () && !_irreducible && !tail ()->is_top ();
1538
+ return !_head->is_Root () &&
1539
+ _head->is_Loop () &&
1540
+ !_head->is_OuterStripMinedLoop () &&
1541
+ !_irreducible &&
1542
+ !tail ()->is_top ();
1538
1543
}
0 commit comments