@@ -1212,7 +1212,13 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
1212
1212
// Limit is not exact.
1213
1213
// Calculate exact limit here.
1214
1214
// Note, counted loop's test is '<' or '>'.
1215
+ #ifdef ASSERT
1216
+ const bool exact_trip_count = cl->has_exact_trip_count ();
1217
+ const uint trip_count = cl->trip_count ();
1215
1218
loop->compute_trip_count (this );
1219
+ assert (exact_trip_count == cl->has_exact_trip_count () && trip_count == cl->trip_count (),
1220
+ " should have computed trip count on Loop Predication entry" );
1221
+ #endif
1216
1222
Node* limit = exact_limit (loop);
1217
1223
int stride = cl->stride ()->get_int ();
1218
1224
@@ -1321,7 +1327,9 @@ IfProjNode* PhaseIdealLoop::add_template_assertion_predicate(IfNode* iff, IdealL
1321
1327
max_value = new AddINode (opaque_init, max_value);
1322
1328
register_new_node (max_value, new_proj);
1323
1329
// init + (current stride - initial stride) is within the loop so narrow its type by leveraging the type of the iv Phi
1324
- max_value = new CastIINode (max_value, loop->_head ->as_CountedLoop ()->phi ()->bottom_type ());
1330
+ const Type* type_iv = loop->_head ->as_CountedLoop ()->phi ()->bottom_type ();
1331
+ assert (!type_iv->is_int ()->is_con (), " constant indicates one loop iteration for which we bailed out earlier" );
1332
+ max_value = new CastIINode (max_value, type_iv);
1325
1333
register_new_node (max_value, parse_predicate_proj);
1326
1334
1327
1335
bol = rc_predicate (new_proj, scale, offset, max_value, limit, stride, rng, (stride > 0 ) != (scale > 0 ),
@@ -1350,12 +1358,21 @@ bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree* loop) {
1350
1358
CountedLoopNode *cl = nullptr ;
1351
1359
if (head->is_valid_counted_loop (T_INT)) {
1352
1360
cl = head->as_CountedLoop ();
1353
- // do nothing for iteration-splitted loops
1354
- if (!cl->is_normal_loop ()) return false ;
1361
+ if (!cl->is_normal_loop ()) {
1362
+ // Do nothing for iteration-splitted loops
1363
+ return false ;
1364
+ }
1365
+ loop->compute_trip_count (this );
1366
+ if (cl->trip_count () == 1 ) {
1367
+ // Not worth to hoist checks out of a loop that is only run for one iteration since the checks are only going to
1368
+ // be executed once anyway.
1369
+ return false ;
1370
+ }
1355
1371
// Avoid RCE if Counted loop's test is '!='.
1356
1372
BoolTest::mask bt = cl->loopexit ()->test_trip ();
1357
- if (bt != BoolTest::lt && bt != BoolTest::gt)
1373
+ if (bt != BoolTest::lt && bt != BoolTest::gt) {
1358
1374
cl = nullptr ;
1375
+ }
1359
1376
}
1360
1377
1361
1378
Node* entry = head->skip_strip_mined ()->in (LoopNode::EntryControl);
0 commit comments