23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/barrierSet.hpp" 27 #include "gc/shared/c2/barrierSetC2.hpp" 28 #include "memory/allocation.inline.hpp" 29 #include "memory/resourceArea.hpp" 30 #include "opto/addnode.hpp" 31 #include "opto/callnode.hpp" 32 #include "opto/castnode.hpp" 33 #include "opto/connode.hpp" 34 #include "opto/castnode.hpp" 35 #include "opto/divnode.hpp" 36 #include "opto/loopnode.hpp" 37 #include "opto/matcher.hpp" 38 #include "opto/mulnode.hpp" 39 #include "opto/movenode.hpp" 40 #include "opto/opaquenode.hpp" 41 #include "opto/rootnode.hpp" 42 #include "opto/subnode.hpp" 43 44 //============================================================================= 45 //------------------------------split_thru_phi--------------------------------- 46 // Split Node 'n' through merge point if there is enough win. 47 Node *PhaseIdealLoop::split_thru_phi( Node *n, Node *region, int policy ) { 48 if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) { 49 // ConvI2L may have type information on it which is unsafe to push up 50 // so disable this for now 51 return NULL; 52 } 53 54 // Splitting range check CastIIs through a loop induction Phi can 55 // cause new Phis to be created that are left unrelated to the loop 56 // induction Phi and prevent optimizations (vectorization) 57 if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() && 58 region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) { 59 return NULL; 60 } 61 62 int wins = 0; 1109 // into LoopNodes. 1110 IdealLoopTree *n_loop = get_loop(n_ctrl); 1111 for (uint j = 1; j < n_ctrl->req(); j++) { 1112 if (get_loop(n_ctrl->in(j)) != n_loop) { 1113 return false; 1114 } 1115 } 1116 1117 // Check for safety of the merge point. 1118 if (!merge_point_safe(n_ctrl)) { 1119 return false; 1120 } 1121 1122 return true; 1123 } 1124 1125 //------------------------------split_if_with_blocks_post---------------------- 1126 // Do the real work in a non-recursive function. CFG hackery wants to be 1127 // in the post-order, so it can dirty the I-DOM info and not use the dirtied 1128 // info. 1129 void PhaseIdealLoop::split_if_with_blocks_post(Node *n) { 1130 1131 // Cloning Cmp through Phi's involves the split-if transform. 1132 // FastLock is not used by an If 1133 if (n->is_Cmp() && !n->is_FastLock()) { 1134 Node *n_ctrl = get_ctrl(n); 1135 // Determine if the Node has inputs from some local Phi. 1136 // Returns the block to clone thru. 1137 Node *n_blk = has_local_phi_input(n); 1138 if (n_blk != n_ctrl) { 1139 return; 1140 } 1141 1142 if (!can_split_if(n_ctrl)) { 1143 return; 1144 } 1145 1146 if (n->outcnt() != 1) { 1147 return; // Multiple bool's from 1 compare? 1148 } 1149 Node *bol = n->unique_out(); 1150 assert(bol->is_Bool(), "expect a bool here"); 1151 if (bol->outcnt() != 1) { 1152 return;// Multiple branches from 1 compare? 1153 } 1360 // to fold a StoreP and an AddP together (as part of an 1361 // address expression) and the AddP and StoreP have 1362 // different controls. 1363 if (!x->is_Load() && !x->is_DecodeNarrowPtr()) _igvn._worklist.yank(x); 1364 } 1365 _igvn.remove_dead_node(n); 1366 } 1367 } 1368 } 1369 } 1370 1371 try_move_store_after_loop(n); 1372 1373 // Check for Opaque2's who's loop has disappeared - who's input is in the 1374 // same loop nest as their output. Remove 'em, they are no longer useful. 1375 if( n_op == Op_Opaque2 && 1376 n->in(1) != NULL && 1377 get_loop(get_ctrl(n)) == get_loop(get_ctrl(n->in(1))) ) { 1378 _igvn.replace_node( n, n->in(1) ); 1379 } 1380 } 1381 1382 //------------------------------split_if_with_blocks--------------------------- 1383 // Check for aggressive application of 'split-if' optimization, 1384 // using basic block level info. 1385 void PhaseIdealLoop::split_if_with_blocks( VectorSet &visited, Node_Stack &nstack ) { 1386 Node *n = C->root(); 1387 visited.set(n->_idx); // first, mark node as visited 1388 // Do pre-visit work for root 1389 n = split_if_with_blocks_pre( n ); 1390 uint cnt = n->outcnt(); 1391 uint i = 0; 1392 while (true) { 1393 // Visit all children 1394 if (i < cnt) { 1395 Node* use = n->raw_out(i); 1396 ++i; 1397 if (use->outcnt() != 0 && !visited.test_set(use->_idx)) { 1398 // Now do pre-visit work for this use 1399 use = split_if_with_blocks_pre( use ); 1400 nstack.push(n, i); // Save parent and next use's index. 1401 n = use; // Process all children of current use. 1402 cnt = use->outcnt(); 1403 i = 0; 1404 } 1405 } 1406 else { 1407 // All of n's children have been processed, complete post-processing. 1408 if (cnt != 0 && !n->is_Con()) { 1409 assert(has_node(n), "no dead nodes"); 1410 split_if_with_blocks_post( n ); 1411 } 1412 if (nstack.is_empty()) { 1413 // Finished all nodes on stack. 1414 break; 1415 } 1416 // Get saved parent node and next use's index. Visit the rest of uses. 1417 n = nstack.node(); 1418 cnt = n->outcnt(); 1419 i = nstack.index(); 1420 nstack.pop(); 1421 } 1422 } 1423 } 1424 1425 1426 //============================================================================= 1427 // 1428 // C L O N E A L O O P B O D Y 1429 // 1430 | 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/barrierSet.hpp" 27 #include "gc/shared/c2/barrierSetC2.hpp" 28 #include "memory/allocation.inline.hpp" 29 #include "memory/resourceArea.hpp" 30 #include "opto/addnode.hpp" 31 #include "opto/callnode.hpp" 32 #include "opto/castnode.hpp" 33 #include "opto/connode.hpp" 34 #include "opto/castnode.hpp" 35 #include "opto/divnode.hpp" 36 #include "opto/loopnode.hpp" 37 #include "opto/matcher.hpp" 38 #include "opto/mulnode.hpp" 39 #include "opto/movenode.hpp" 40 #include "opto/opaquenode.hpp" 41 #include "opto/rootnode.hpp" 42 #include "opto/subnode.hpp" 43 #include "utilities/macros.hpp" 44 #if INCLUDE_ZGC 45 #include "gc/z/c2/zBarrierSetC2.hpp" 46 #endif 47 48 //============================================================================= 49 //------------------------------split_thru_phi--------------------------------- 50 // Split Node 'n' through merge point if there is enough win. 51 Node *PhaseIdealLoop::split_thru_phi( Node *n, Node *region, int policy ) { 52 if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) { 53 // ConvI2L may have type information on it which is unsafe to push up 54 // so disable this for now 55 return NULL; 56 } 57 58 // Splitting range check CastIIs through a loop induction Phi can 59 // cause new Phis to be created that are left unrelated to the loop 60 // induction Phi and prevent optimizations (vectorization) 61 if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() && 62 region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) { 63 return NULL; 64 } 65 66 int wins = 0; 1113 // into LoopNodes. 1114 IdealLoopTree *n_loop = get_loop(n_ctrl); 1115 for (uint j = 1; j < n_ctrl->req(); j++) { 1116 if (get_loop(n_ctrl->in(j)) != n_loop) { 1117 return false; 1118 } 1119 } 1120 1121 // Check for safety of the merge point. 1122 if (!merge_point_safe(n_ctrl)) { 1123 return false; 1124 } 1125 1126 return true; 1127 } 1128 1129 //------------------------------split_if_with_blocks_post---------------------- 1130 // Do the real work in a non-recursive function. CFG hackery wants to be 1131 // in the post-order, so it can dirty the I-DOM info and not use the dirtied 1132 // info. 1133 void PhaseIdealLoop::split_if_with_blocks_post(Node *n, bool last_round) { 1134 1135 // Cloning Cmp through Phi's involves the split-if transform. 1136 // FastLock is not used by an If 1137 if (n->is_Cmp() && !n->is_FastLock() && !last_round) { 1138 Node *n_ctrl = get_ctrl(n); 1139 // Determine if the Node has inputs from some local Phi. 1140 // Returns the block to clone thru. 1141 Node *n_blk = has_local_phi_input(n); 1142 if (n_blk != n_ctrl) { 1143 return; 1144 } 1145 1146 if (!can_split_if(n_ctrl)) { 1147 return; 1148 } 1149 1150 if (n->outcnt() != 1) { 1151 return; // Multiple bool's from 1 compare? 1152 } 1153 Node *bol = n->unique_out(); 1154 assert(bol->is_Bool(), "expect a bool here"); 1155 if (bol->outcnt() != 1) { 1156 return;// Multiple branches from 1 compare? 1157 } 1364 // to fold a StoreP and an AddP together (as part of an 1365 // address expression) and the AddP and StoreP have 1366 // different controls. 1367 if (!x->is_Load() && !x->is_DecodeNarrowPtr()) _igvn._worklist.yank(x); 1368 } 1369 _igvn.remove_dead_node(n); 1370 } 1371 } 1372 } 1373 } 1374 1375 try_move_store_after_loop(n); 1376 1377 // Check for Opaque2's who's loop has disappeared - who's input is in the 1378 // same loop nest as their output. Remove 'em, they are no longer useful. 1379 if( n_op == Op_Opaque2 && 1380 n->in(1) != NULL && 1381 get_loop(get_ctrl(n)) == get_loop(get_ctrl(n->in(1))) ) { 1382 _igvn.replace_node( n, n->in(1) ); 1383 } 1384 1385 #if INCLUDE_ZGC 1386 if (UseZGC) { 1387 ZBarrierSetC2::loop_optimize_gc_barrier(this, n, last_round); 1388 } 1389 #endif 1390 } 1391 1392 //------------------------------split_if_with_blocks--------------------------- 1393 // Check for aggressive application of 'split-if' optimization, 1394 // using basic block level info. 1395 void PhaseIdealLoop::split_if_with_blocks(VectorSet &visited, Node_Stack &nstack, bool last_round) { 1396 Node *n = C->root(); 1397 visited.set(n->_idx); // first, mark node as visited 1398 // Do pre-visit work for root 1399 n = split_if_with_blocks_pre( n ); 1400 uint cnt = n->outcnt(); 1401 uint i = 0; 1402 while (true) { 1403 // Visit all children 1404 if (i < cnt) { 1405 Node* use = n->raw_out(i); 1406 ++i; 1407 if (use->outcnt() != 0 && !visited.test_set(use->_idx)) { 1408 // Now do pre-visit work for this use 1409 use = split_if_with_blocks_pre( use ); 1410 nstack.push(n, i); // Save parent and next use's index. 1411 n = use; // Process all children of current use. 1412 cnt = use->outcnt(); 1413 i = 0; 1414 } 1415 } 1416 else { 1417 // All of n's children have been processed, complete post-processing. 1418 if (cnt != 0 && !n->is_Con()) { 1419 assert(has_node(n), "no dead nodes"); 1420 split_if_with_blocks_post( n, last_round ); 1421 } 1422 if (nstack.is_empty()) { 1423 // Finished all nodes on stack. 1424 break; 1425 } 1426 // Get saved parent node and next use's index. Visit the rest of uses. 1427 n = nstack.node(); 1428 cnt = n->outcnt(); 1429 i = nstack.index(); 1430 nstack.pop(); 1431 } 1432 } 1433 } 1434 1435 1436 //============================================================================= 1437 // 1438 // C L O N E A L O O P B O D Y 1439 // 1440 |