< prev index next >

src/hotspot/share/opto/phaseX.cpp

Print this page

1164     // SubNode::Value
1165     // CmpPNode::sub
1166     // MemNode::detect_ptr_independence
1167     // MemNode::all_controls_dominate
1168     // We find all controls of a pointer load, and see if they dominate the control of
1169     // an allocation. If they all dominate, we know the allocation is after (independent)
1170     // of the pointer load, and we can say the pointers are different. For this we call
1171     // n->dominates(sub, nlist) to check if controls n of the pointer load dominate the
1172     // control sub of the allocation. The problems is that sometimes dominates answers
1173     // false conservatively, and later it can determine that it is indeed true. Loops with
1174     // Region heads can lead to giving up, whereas LoopNodes can be skipped easier, and
1175     // so the traversal becomes more powerful. This is difficult to remidy, we would have
1176     // to notify the CmpP of CFG updates. Luckily, we recompute CmpP::Value during CCP
1177     // after loop-opts, so that should take care of many of these cases.
1178     return false;
1179   }
1180 
1181   stringStream ss; // Print as a block without tty lock.
1182   ss.cr();
1183   ss.print_cr("Missed Value optimization:");
1184   n->dump_bfs(1, nullptr, "", &ss);
1185   ss.print_cr("Current type:");
1186   told->dump_on(&ss);
1187   ss.cr();
1188   ss.print_cr("Optimized type:");
1189   tnew->dump_on(&ss);
1190   ss.cr();
1191   tty->print_cr("%s", ss.as_string());
1192   return true;
1193 }
1194 
1195 // Check that all Ideal optimizations that could be done were done.
1196 // Returns true if it found missed optimization opportunities and
1197 //         false otherwise (no missed optimization, or skipped verification).
1198 bool PhaseIterGVN::verify_Ideal_for(Node* n, bool can_reshape) {
1199   // First, we check a list of exceptions, where we skip verification,
1200   // because there are known cases where Ideal can optimize after IGVN.
1201   // Some may be expected and cannot be fixed, and others should be fixed.
1202   switch (n->Opcode()) {
1203     // RangeCheckNode::Ideal looks up the chain for about 999 nodes
1204     // (see "Range-Check scan limit"). So, it is possible that something

2057   i->dump_bfs(1, nullptr, "", &ss);
2058   tty->print_cr("%s", ss.as_string());
2059   return true;
2060 }
2061 #endif
2062 
2063 /**
2064  * Register a new node with the optimizer.  Update the types array, the def-use
2065  * info.  Put on worklist.
2066  */
2067 Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) {
2068   set_type_bottom(n);
2069   _worklist.push(n);
2070   if (orig != nullptr)  C->copy_node_notes_to(n, orig);
2071   return n;
2072 }
2073 
2074 //------------------------------transform--------------------------------------
2075 // Non-recursive: idealize Node 'n' with respect to its inputs and its value
2076 Node *PhaseIterGVN::transform( Node *n ) {
2077   if (_delay_transform) {
2078     // Register the node but don't optimize for now
2079     register_new_node_with_optimizer(n);
2080     return n;
2081   }
2082 
2083   // If brand new node, make space in type array, and give it a type.
2084   ensure_type_or_null(n);
2085   if (type_or_null(n) == nullptr) {
2086     set_type_bottom(n);
2087   }
2088 






2089   return transform_old(n);
2090 }
2091 
2092 Node *PhaseIterGVN::transform_old(Node* n) {
2093   NOT_PRODUCT(set_transforms());
2094   // Remove 'n' from hash table in case it gets modified
2095   _table.hash_delete(n);
2096 #ifdef ASSERT
2097   if (is_verify_def_use()) {
2098     assert(!_table.find_index(n->_idx), "found duplicate entry in table");
2099   }
2100 #endif
2101 
2102   // Allow Bool -> Cmp idealisation in late inlining intrinsics that return a bool
2103   if (n->is_Cmp()) {
2104     add_users_to_worklist(n);
2105   }
2106 
2107   // Apply the Ideal call in a loop until it no longer applies
2108   Node* k = n;

2341 
2342   // Smash all inputs to 'old', isolating him completely
2343   Node *temp = new Node(1);
2344   temp->init_req(0,nn);     // Add a use to nn to prevent him from dying
2345   remove_dead_node( old );
2346   temp->del_req(0);         // Yank bogus edge
2347   if (nn != nullptr && nn->outcnt() == 0) {
2348     _worklist.push(nn);
2349   }
2350 #ifndef PRODUCT
2351   if (is_verify_def_use()) {
2352     for ( int i = 0; i < _verify_window_size; i++ ) {
2353       if ( _verify_window[i] == old )
2354         _verify_window[i] = nn;
2355     }
2356   }
2357 #endif
2358   temp->destruct(this);     // reuse the _idx of this little guy
2359 }
2360 













2361 //------------------------------add_users_to_worklist--------------------------
2362 void PhaseIterGVN::add_users_to_worklist0(Node* n, Unique_Node_List& worklist) {
2363   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2364     worklist.push(n->fast_out(i));  // Push on worklist
2365   }
2366 }
2367 
2368 // Return counted loop Phi if as a counted loop exit condition, cmp
2369 // compares the induction variable with n
2370 static PhiNode* countedloop_phi_from_cmp(CmpNode* cmp, Node* n) {
2371   for (DUIterator_Fast imax, i = cmp->fast_outs(imax); i < imax; i++) {
2372     Node* bol = cmp->fast_out(i);
2373     for (DUIterator_Fast i2max, i2 = bol->fast_outs(i2max); i2 < i2max; i2++) {
2374       Node* iff = bol->fast_out(i2);
2375       if (iff->is_BaseCountedLoopEnd()) {
2376         BaseCountedLoopEndNode* cle = iff->as_BaseCountedLoopEnd();
2377         if (cle->limit() == n) {
2378           PhiNode* phi = cle->phi();
2379           if (phi != nullptr) {
2380             return phi;

2396     add_users_of_use_to_worklist(n, use, worklist);
2397   }
2398 }
2399 
2400 void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist) {
2401   if(use->is_Multi() ||      // Multi-definer?  Push projs on worklist
2402       use->is_Store() )       // Enable store/load same address
2403     add_users_to_worklist0(use, worklist);
2404 
2405   // If we changed the receiver type to a call, we need to revisit
2406   // the Catch following the call.  It's looking for a non-null
2407   // receiver to know when to enable the regular fall-through path
2408   // in addition to the NullPtrException path.
2409   if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) {
2410     Node* p = use->as_CallDynamicJava()->proj_out_or_null(TypeFunc::Control);
2411     if (p != nullptr) {
2412       add_users_to_worklist0(p, worklist);
2413     }
2414   }
2415 










2416   uint use_op = use->Opcode();
2417   if(use->is_Cmp()) {       // Enable CMP/BOOL optimization
2418     add_users_to_worklist0(use, worklist); // Put Bool on worklist
2419     if (use->outcnt() > 0) {
2420       Node* bol = use->raw_out(0);
2421       if (bol->outcnt() > 0) {
2422         Node* iff = bol->raw_out(0);
2423         if (iff->outcnt() == 2) {
2424           // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the
2425           // phi merging either 0 or 1 onto the worklist
2426           Node* ifproj0 = iff->raw_out(0);
2427           Node* ifproj1 = iff->raw_out(1);
2428           if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) {
2429             Node* region0 = ifproj0->raw_out(0);
2430             Node* region1 = ifproj1->raw_out(0);
2431             if( region0 == region1 )
2432               add_users_to_worklist0(region0, worklist);
2433           }
2434         }
2435       }

2493           assert(n == in2, "only in2 modified");
2494           // Find all CastII with input in1.
2495           for (DUIterator_Fast jmax, j = in1->fast_outs(jmax); j < jmax; j++) {
2496             Node* castii = in1->fast_out(j);
2497             if (castii->is_CastII() && castii->as_CastII()->carry_dependency()) {
2498               // Find If.
2499               if (castii->in(0) != nullptr && castii->in(0)->in(0) != nullptr && castii->in(0)->in(0)->is_If()) {
2500                 Node* ifnode = castii->in(0)->in(0);
2501                 // Check that if connects to the cmp
2502                 if (ifnode->in(1) != nullptr && ifnode->in(1)->is_Bool() && ifnode->in(1)->in(1) == cmp) {
2503                   worklist.push(castii);
2504                 }
2505               }
2506             }
2507           }
2508         }
2509       }
2510     }
2511   }
2512 









2513   // If changed Cast input, notify down for Phi, Sub, and Xor - all do "uncast"
2514   // Patterns:
2515   // ConstraintCast+ -> Sub
2516   // ConstraintCast+ -> Phi
2517   // ConstraintCast+ -> Xor
2518   if (use->is_ConstraintCast()) {
2519     auto push_the_uses_to_worklist = [&](Node* n){
2520       if (n->is_Phi() || n->is_Sub() || n->Opcode() == Op_XorI || n->Opcode() == Op_XorL) {
2521         worklist.push(n);
2522       }
2523     };
2524     auto is_boundary = [](Node* n){ return !n->is_ConstraintCast(); };
2525     use->visit_uses(push_the_uses_to_worklist, is_boundary);
2526   }
2527   // If changed LShift inputs, check RShift users for useless sign-ext
2528   if (use_op == Op_LShiftI || use_op == Op_LShiftL) {
2529     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2530       Node* u = use->fast_out(i2);
2531       if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL)
2532         worklist.push(u);

2605   // If the ValidLengthTest input changes then the fallthrough path out of the AllocateArray may have become dead.
2606   // CatchNode::Value() is responsible for killing that path. The CatchNode has to be explicitly enqueued for igvn
2607   // to guarantee the change is not missed.
2608   if (use_op == Op_AllocateArray && n == use->in(AllocateNode::ValidLengthTest)) {
2609     Node* p = use->as_AllocateArray()->proj_out_or_null(TypeFunc::Control);
2610     if (p != nullptr) {
2611       add_users_to_worklist0(p, worklist);
2612     }
2613   }
2614 
2615   if (use_op == Op_Initialize) {
2616     InitializeNode* init = use->as_Initialize();
2617     init->for_each_proj(enqueue_init_mem_projs, TypeFunc::Memory);
2618   }
2619   // Loading the java mirror from a Klass requires two loads and the type
2620   // of the mirror load depends on the type of 'n'. See LoadNode::Value().
2621   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
2622   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2623   bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
2624 








2625   if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
2626     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2627       Node* u = use->fast_out(i2);
2628       const Type* ut = u->bottom_type();
2629       if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
2630         if (has_load_barrier_nodes) {
2631           // Search for load barriers behind the load
2632           for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
2633             Node* b = u->fast_out(i3);
2634             if (bs->is_gc_barrier_node(b)) {
2635               worklist.push(b);
2636             }
2637           }
2638         }
2639         worklist.push(u);
2640       }
2641     }
2642   }










2643   if (use->Opcode() == Op_OpaqueZeroTripGuard) {
2644     assert(use->outcnt() <= 1, "OpaqueZeroTripGuard can't be shared");
2645     if (use->outcnt() == 1) {
2646       Node* cmp = use->unique_out();
2647       worklist.push(cmp);
2648     }
2649   }
2650 
2651   // From CastX2PNode::Ideal
2652   // CastX2P(AddX(x, y))
2653   // CastX2P(SubX(x, y))
2654   if (use->Opcode() == Op_AddX || use->Opcode() == Op_SubX) {
2655     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2656       Node* u = use->fast_out(i2);
2657       if (u->Opcode() == Op_CastX2P) {
2658         worklist.push(u);
2659       }
2660     }
2661   }
2662 

2742 //------------------------------PhaseCCP---------------------------------------
2743 // Conditional Constant Propagation, ala Wegman & Zadeck
2744 PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) {
2745   NOT_PRODUCT( clear_constants(); )
2746   assert( _worklist.size() == 0, "" );
2747   analyze();
2748 }
2749 
2750 #ifndef PRODUCT
2751 //------------------------------~PhaseCCP--------------------------------------
2752 PhaseCCP::~PhaseCCP() {
2753   inc_invokes();
2754   _total_constants += count_constants();
2755 }
2756 #endif
2757 
2758 
2759 #ifdef ASSERT
2760 void PhaseCCP::verify_type(Node* n, const Type* tnew, const Type* told) {
2761   if (tnew->meet(told) != tnew->remove_speculative()) {
2762     n->dump(1);
2763     tty->print("told = "); told->dump(); tty->cr();
2764     tty->print("tnew = "); tnew->dump(); tty->cr();
2765     fatal("Not monotonic");
2766   }
2767   assert(!told->isa_int() || !tnew->isa_int() || told->is_int()->_widen <= tnew->is_int()->_widen, "widen increases");
2768   assert(!told->isa_long() || !tnew->isa_long() || told->is_long()->_widen <= tnew->is_long()->_widen, "widen increases");
2769 }
2770 #endif //ASSERT
2771 
2772 // In this analysis, all types are initially set to TOP. We iteratively call Value() on all nodes of the graph until
2773 // we reach a fixed-point (i.e. no types change anymore). We start with a list that only contains the root node. Each time
2774 // a new type is set, we push all uses of that node back to the worklist (in some cases, we also push grandchildren
2775 // or nodes even further down back to the worklist because their type could change as a result of the current type
2776 // change).
2777 void PhaseCCP::analyze() {
2778   // Initialize all types to TOP, optimistic analysis
2779   for (uint i = 0; i < C->unique(); i++)  {
2780     _types.map(i, Type::TOP);
2781   }
2782 

2864   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2865     Node* use = n->fast_out(i);
2866     push_if_not_bottom_type(worklist, use);
2867     push_more_uses(worklist, n, use);
2868   }
2869 }
2870 
2871 void PhaseCCP::push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const {
2872   if (n->bottom_type() != type(n)) {
2873     worklist.push(n);
2874   }
2875 }
2876 
2877 // For some nodes, we need to propagate the type change to grandchildren or even further down.
2878 // Add them back to the worklist.
2879 void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const {
2880   push_phis(worklist, use);
2881   push_catch(worklist, use);
2882   push_cmpu(worklist, use);
2883   push_counted_loop_phi(worklist, parent, use);

2884   push_loadp(worklist, use);
2885   push_and(worklist, parent, use);
2886   push_cast_ii(worklist, parent, use);
2887   push_opaque_zero_trip_guard(worklist, use);
2888   push_bool_with_cmpu_and_mask(worklist, use);
2889 }
2890 
2891 
2892 // We must recheck Phis too if use is a Region.
2893 void PhaseCCP::push_phis(Unique_Node_List& worklist, const Node* use) const {
2894   if (use->is_Region()) {
2895     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2896       push_if_not_bottom_type(worklist, use->fast_out(i));
2897     }
2898   }
2899 }
2900 
2901 // If we changed the receiver type to a call, we need to revisit the Catch node following the call. It's looking for a
2902 // non-null receiver to know when to enable the regular fall-through path in addition to the NullPtrException path.
2903 // Same is true if the type of a ValidLengthTest input to an AllocateArrayNode changes.

2975       continue;
2976     }
2977 
2978     Node* m = addI->in(1);
2979     if (m == andI->in(1) || m == andI->in(2)) {
2980       // Is "m" shared? Matched (1b) and thus we revisit Bool.
2981       push_if_not_bottom_type(worklist, bol);
2982     }
2983   }
2984 }
2985 
2986 // If n is used in a counted loop exit condition, then the type of the counted loop's Phi depends on the type of 'n'.
2987 // Seem PhiNode::Value().
2988 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
2989   uint use_op = use->Opcode();
2990   if (use_op == Op_CmpI || use_op == Op_CmpL) {
2991     PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
2992     if (phi != nullptr) {
2993       worklist.push(phi);
2994     }












2995   }
2996 }
2997 
2998 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
2999 // See LoadNode::Value().
3000 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
3001   BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
3002   bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
3003 
3004   if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
3005     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
3006       Node* loadp = use->fast_out(i);
3007       const Type* ut = loadp->bottom_type();
3008       if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
3009         if (has_load_barrier_nodes) {
3010           // Search for load barriers behind the load
3011           push_load_barrier(worklist, barrier_set, loadp);
3012         }
3013         worklist.push(loadp);
3014       }

1164     // SubNode::Value
1165     // CmpPNode::sub
1166     // MemNode::detect_ptr_independence
1167     // MemNode::all_controls_dominate
1168     // We find all controls of a pointer load, and see if they dominate the control of
1169     // an allocation. If they all dominate, we know the allocation is after (independent)
1170     // of the pointer load, and we can say the pointers are different. For this we call
1171     // n->dominates(sub, nlist) to check if controls n of the pointer load dominate the
1172     // control sub of the allocation. The problems is that sometimes dominates answers
1173     // false conservatively, and later it can determine that it is indeed true. Loops with
1174     // Region heads can lead to giving up, whereas LoopNodes can be skipped easier, and
1175     // so the traversal becomes more powerful. This is difficult to remidy, we would have
1176     // to notify the CmpP of CFG updates. Luckily, we recompute CmpP::Value during CCP
1177     // after loop-opts, so that should take care of many of these cases.
1178     return false;
1179   }
1180 
1181   stringStream ss; // Print as a block without tty lock.
1182   ss.cr();
1183   ss.print_cr("Missed Value optimization:");
1184   n->dump_bfs(3, nullptr, "", &ss);
1185   ss.print_cr("Current type:");
1186   told->dump_on(&ss);
1187   ss.cr();
1188   ss.print_cr("Optimized type:");
1189   tnew->dump_on(&ss);
1190   ss.cr();
1191   tty->print_cr("%s", ss.as_string());
1192   return true;
1193 }
1194 
1195 // Check that all Ideal optimizations that could be done were done.
1196 // Returns true if it found missed optimization opportunities and
1197 //         false otherwise (no missed optimization, or skipped verification).
1198 bool PhaseIterGVN::verify_Ideal_for(Node* n, bool can_reshape) {
1199   // First, we check a list of exceptions, where we skip verification,
1200   // because there are known cases where Ideal can optimize after IGVN.
1201   // Some may be expected and cannot be fixed, and others should be fixed.
1202   switch (n->Opcode()) {
1203     // RangeCheckNode::Ideal looks up the chain for about 999 nodes
1204     // (see "Range-Check scan limit"). So, it is possible that something

2057   i->dump_bfs(1, nullptr, "", &ss);
2058   tty->print_cr("%s", ss.as_string());
2059   return true;
2060 }
2061 #endif
2062 
2063 /**
2064  * Register a new node with the optimizer.  Update the types array, the def-use
2065  * info.  Put on worklist.
2066  */
2067 Node* PhaseIterGVN::register_new_node_with_optimizer(Node* n, Node* orig) {
2068   set_type_bottom(n);
2069   _worklist.push(n);
2070   if (orig != nullptr)  C->copy_node_notes_to(n, orig);
2071   return n;
2072 }
2073 
2074 //------------------------------transform--------------------------------------
2075 // Non-recursive: idealize Node 'n' with respect to its inputs and its value
2076 Node *PhaseIterGVN::transform( Node *n ) {






2077   // If brand new node, make space in type array, and give it a type.
2078   ensure_type_or_null(n);
2079   if (type_or_null(n) == nullptr) {
2080     set_type_bottom(n);
2081   }
2082 
2083   if (_delay_transform) {
2084     // Add the node to the worklist but don't optimize for now
2085     _worklist.push(n);
2086     return n;
2087   }
2088 
2089   return transform_old(n);
2090 }
2091 
2092 Node *PhaseIterGVN::transform_old(Node* n) {
2093   NOT_PRODUCT(set_transforms());
2094   // Remove 'n' from hash table in case it gets modified
2095   _table.hash_delete(n);
2096 #ifdef ASSERT
2097   if (is_verify_def_use()) {
2098     assert(!_table.find_index(n->_idx), "found duplicate entry in table");
2099   }
2100 #endif
2101 
2102   // Allow Bool -> Cmp idealisation in late inlining intrinsics that return a bool
2103   if (n->is_Cmp()) {
2104     add_users_to_worklist(n);
2105   }
2106 
2107   // Apply the Ideal call in a loop until it no longer applies
2108   Node* k = n;

2341 
2342   // Smash all inputs to 'old', isolating him completely
2343   Node *temp = new Node(1);
2344   temp->init_req(0,nn);     // Add a use to nn to prevent him from dying
2345   remove_dead_node( old );
2346   temp->del_req(0);         // Yank bogus edge
2347   if (nn != nullptr && nn->outcnt() == 0) {
2348     _worklist.push(nn);
2349   }
2350 #ifndef PRODUCT
2351   if (is_verify_def_use()) {
2352     for ( int i = 0; i < _verify_window_size; i++ ) {
2353       if ( _verify_window[i] == old )
2354         _verify_window[i] = nn;
2355     }
2356   }
2357 #endif
2358   temp->destruct(this);     // reuse the _idx of this little guy
2359 }
2360 
2361 void PhaseIterGVN::replace_in_uses(Node* n, Node* m) {
2362   assert(n != nullptr, "sanity");
2363   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2364     Node* u = n->fast_out(i);
2365     if (u != n) {
2366       rehash_node_delayed(u);
2367       int nb = u->replace_edge(n, m);
2368       --i, imax -= nb;
2369     }
2370   }
2371   assert(n->outcnt() == 0, "all uses must be deleted");
2372 }
2373 
2374 //------------------------------add_users_to_worklist--------------------------
2375 void PhaseIterGVN::add_users_to_worklist0(Node* n, Unique_Node_List& worklist) {
2376   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2377     worklist.push(n->fast_out(i));  // Push on worklist
2378   }
2379 }
2380 
2381 // Return counted loop Phi if as a counted loop exit condition, cmp
2382 // compares the induction variable with n
2383 static PhiNode* countedloop_phi_from_cmp(CmpNode* cmp, Node* n) {
2384   for (DUIterator_Fast imax, i = cmp->fast_outs(imax); i < imax; i++) {
2385     Node* bol = cmp->fast_out(i);
2386     for (DUIterator_Fast i2max, i2 = bol->fast_outs(i2max); i2 < i2max; i2++) {
2387       Node* iff = bol->fast_out(i2);
2388       if (iff->is_BaseCountedLoopEnd()) {
2389         BaseCountedLoopEndNode* cle = iff->as_BaseCountedLoopEnd();
2390         if (cle->limit() == n) {
2391           PhiNode* phi = cle->phi();
2392           if (phi != nullptr) {
2393             return phi;

2409     add_users_of_use_to_worklist(n, use, worklist);
2410   }
2411 }
2412 
2413 void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist) {
2414   if(use->is_Multi() ||      // Multi-definer?  Push projs on worklist
2415       use->is_Store() )       // Enable store/load same address
2416     add_users_to_worklist0(use, worklist);
2417 
2418   // If we changed the receiver type to a call, we need to revisit
2419   // the Catch following the call.  It's looking for a non-null
2420   // receiver to know when to enable the regular fall-through path
2421   // in addition to the NullPtrException path.
2422   if (use->is_CallDynamicJava() && n == use->in(TypeFunc::Parms)) {
2423     Node* p = use->as_CallDynamicJava()->proj_out_or_null(TypeFunc::Control);
2424     if (p != nullptr) {
2425       add_users_to_worklist0(p, worklist);
2426     }
2427   }
2428 
2429   // AndLNode::Ideal folds GraphKit::mark_word_test patterns. Give it a chance to run.
2430   if (n->is_Load() && use->is_Phi()) {
2431     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2432       Node* u = use->fast_out(i);
2433       if (u->Opcode() == Op_AndL) {
2434         worklist.push(u);
2435       }
2436     }
2437   }
2438 
2439   uint use_op = use->Opcode();
2440   if(use->is_Cmp()) {       // Enable CMP/BOOL optimization
2441     add_users_to_worklist0(use, worklist); // Put Bool on worklist
2442     if (use->outcnt() > 0) {
2443       Node* bol = use->raw_out(0);
2444       if (bol->outcnt() > 0) {
2445         Node* iff = bol->raw_out(0);
2446         if (iff->outcnt() == 2) {
2447           // Look for the 'is_x2logic' pattern: "x ? : 0 : 1" and put the
2448           // phi merging either 0 or 1 onto the worklist
2449           Node* ifproj0 = iff->raw_out(0);
2450           Node* ifproj1 = iff->raw_out(1);
2451           if (ifproj0->outcnt() > 0 && ifproj1->outcnt() > 0) {
2452             Node* region0 = ifproj0->raw_out(0);
2453             Node* region1 = ifproj1->raw_out(0);
2454             if( region0 == region1 )
2455               add_users_to_worklist0(region0, worklist);
2456           }
2457         }
2458       }

2516           assert(n == in2, "only in2 modified");
2517           // Find all CastII with input in1.
2518           for (DUIterator_Fast jmax, j = in1->fast_outs(jmax); j < jmax; j++) {
2519             Node* castii = in1->fast_out(j);
2520             if (castii->is_CastII() && castii->as_CastII()->carry_dependency()) {
2521               // Find If.
2522               if (castii->in(0) != nullptr && castii->in(0)->in(0) != nullptr && castii->in(0)->in(0)->is_If()) {
2523                 Node* ifnode = castii->in(0)->in(0);
2524                 // Check that if connects to the cmp
2525                 if (ifnode->in(1) != nullptr && ifnode->in(1)->is_Bool() && ifnode->in(1)->in(1) == cmp) {
2526                   worklist.push(castii);
2527                 }
2528               }
2529             }
2530           }
2531         }
2532       }
2533     }
2534   }
2535 
2536   // Inline type nodes can have other inline types as users. If an input gets
2537   // updated, make sure that inline type users get a chance for optimization.
2538   if (use->is_InlineType()) {
2539     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2540       Node* u = use->fast_out(i2);
2541       if (u->is_InlineType())
2542         worklist.push(u);
2543     }
2544   }
2545   // If changed Cast input, notify down for Phi, Sub, and Xor - all do "uncast"
2546   // Patterns:
2547   // ConstraintCast+ -> Sub
2548   // ConstraintCast+ -> Phi
2549   // ConstraintCast+ -> Xor
2550   if (use->is_ConstraintCast()) {
2551     auto push_the_uses_to_worklist = [&](Node* n){
2552       if (n->is_Phi() || n->is_Sub() || n->Opcode() == Op_XorI || n->Opcode() == Op_XorL) {
2553         worklist.push(n);
2554       }
2555     };
2556     auto is_boundary = [](Node* n){ return !n->is_ConstraintCast(); };
2557     use->visit_uses(push_the_uses_to_worklist, is_boundary);
2558   }
2559   // If changed LShift inputs, check RShift users for useless sign-ext
2560   if (use_op == Op_LShiftI || use_op == Op_LShiftL) {
2561     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2562       Node* u = use->fast_out(i2);
2563       if (u->Opcode() == Op_RShiftI || u->Opcode() == Op_RShiftL)
2564         worklist.push(u);

2637   // If the ValidLengthTest input changes then the fallthrough path out of the AllocateArray may have become dead.
2638   // CatchNode::Value() is responsible for killing that path. The CatchNode has to be explicitly enqueued for igvn
2639   // to guarantee the change is not missed.
2640   if (use_op == Op_AllocateArray && n == use->in(AllocateNode::ValidLengthTest)) {
2641     Node* p = use->as_AllocateArray()->proj_out_or_null(TypeFunc::Control);
2642     if (p != nullptr) {
2643       add_users_to_worklist0(p, worklist);
2644     }
2645   }
2646 
2647   if (use_op == Op_Initialize) {
2648     InitializeNode* init = use->as_Initialize();
2649     init->for_each_proj(enqueue_init_mem_projs, TypeFunc::Memory);
2650   }
2651   // Loading the java mirror from a Klass requires two loads and the type
2652   // of the mirror load depends on the type of 'n'. See LoadNode::Value().
2653   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
2654   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2655   bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
2656 
2657   if (use_op == Op_CastP2X) {
2658     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2659       Node* u = use->fast_out(i2);
2660       if (u->Opcode() == Op_AndX) {
2661         worklist.push(u);
2662       }
2663     }
2664   }
2665   if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
2666     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2667       Node* u = use->fast_out(i2);
2668       const Type* ut = u->bottom_type();
2669       if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
2670         if (has_load_barrier_nodes) {
2671           // Search for load barriers behind the load
2672           for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
2673             Node* b = u->fast_out(i3);
2674             if (bs->is_gc_barrier_node(b)) {
2675               worklist.push(b);
2676             }
2677           }
2678         }
2679         worklist.push(u);
2680       }
2681     }
2682   }
2683   // Give CallStaticJavaNode::remove_useless_allocation a chance to run
2684   if (use->is_Region()) {
2685     Node* c = use;
2686     do {
2687       c = c->unique_ctrl_out_or_null();
2688     } while (c != nullptr && c->is_Region());
2689     if (c != nullptr && c->is_CallStaticJava() && c->as_CallStaticJava()->uncommon_trap_request() != 0) {
2690       worklist.push(c);
2691     }
2692   }
2693   if (use->Opcode() == Op_OpaqueZeroTripGuard) {
2694     assert(use->outcnt() <= 1, "OpaqueZeroTripGuard can't be shared");
2695     if (use->outcnt() == 1) {
2696       Node* cmp = use->unique_out();
2697       worklist.push(cmp);
2698     }
2699   }
2700 
2701   // From CastX2PNode::Ideal
2702   // CastX2P(AddX(x, y))
2703   // CastX2P(SubX(x, y))
2704   if (use->Opcode() == Op_AddX || use->Opcode() == Op_SubX) {
2705     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2706       Node* u = use->fast_out(i2);
2707       if (u->Opcode() == Op_CastX2P) {
2708         worklist.push(u);
2709       }
2710     }
2711   }
2712 

2792 //------------------------------PhaseCCP---------------------------------------
2793 // Conditional Constant Propagation, ala Wegman & Zadeck
2794 PhaseCCP::PhaseCCP( PhaseIterGVN *igvn ) : PhaseIterGVN(igvn) {
2795   NOT_PRODUCT( clear_constants(); )
2796   assert( _worklist.size() == 0, "" );
2797   analyze();
2798 }
2799 
2800 #ifndef PRODUCT
2801 //------------------------------~PhaseCCP--------------------------------------
2802 PhaseCCP::~PhaseCCP() {
2803   inc_invokes();
2804   _total_constants += count_constants();
2805 }
2806 #endif
2807 
2808 
2809 #ifdef ASSERT
2810 void PhaseCCP::verify_type(Node* n, const Type* tnew, const Type* told) {
2811   if (tnew->meet(told) != tnew->remove_speculative()) {
2812     n->dump(3);
2813     tty->print("told = "); told->dump(); tty->cr();
2814     tty->print("tnew = "); tnew->dump(); tty->cr();
2815     fatal("Not monotonic");
2816   }
2817   assert(!told->isa_int() || !tnew->isa_int() || told->is_int()->_widen <= tnew->is_int()->_widen, "widen increases");
2818   assert(!told->isa_long() || !tnew->isa_long() || told->is_long()->_widen <= tnew->is_long()->_widen, "widen increases");
2819 }
2820 #endif //ASSERT
2821 
2822 // In this analysis, all types are initially set to TOP. We iteratively call Value() on all nodes of the graph until
2823 // we reach a fixed-point (i.e. no types change anymore). We start with a list that only contains the root node. Each time
2824 // a new type is set, we push all uses of that node back to the worklist (in some cases, we also push grandchildren
2825 // or nodes even further down back to the worklist because their type could change as a result of the current type
2826 // change).
2827 void PhaseCCP::analyze() {
2828   // Initialize all types to TOP, optimistic analysis
2829   for (uint i = 0; i < C->unique(); i++)  {
2830     _types.map(i, Type::TOP);
2831   }
2832 

2914   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2915     Node* use = n->fast_out(i);
2916     push_if_not_bottom_type(worklist, use);
2917     push_more_uses(worklist, n, use);
2918   }
2919 }
2920 
2921 void PhaseCCP::push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const {
2922   if (n->bottom_type() != type(n)) {
2923     worklist.push(n);
2924   }
2925 }
2926 
2927 // For some nodes, we need to propagate the type change to grandchildren or even further down.
2928 // Add them back to the worklist.
2929 void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const {
2930   push_phis(worklist, use);
2931   push_catch(worklist, use);
2932   push_cmpu(worklist, use);
2933   push_counted_loop_phi(worklist, parent, use);
2934   push_cast(worklist, use);
2935   push_loadp(worklist, use);
2936   push_and(worklist, parent, use);
2937   push_cast_ii(worklist, parent, use);
2938   push_opaque_zero_trip_guard(worklist, use);
2939   push_bool_with_cmpu_and_mask(worklist, use);
2940 }
2941 
2942 
2943 // We must recheck Phis too if use is a Region.
2944 void PhaseCCP::push_phis(Unique_Node_List& worklist, const Node* use) const {
2945   if (use->is_Region()) {
2946     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2947       push_if_not_bottom_type(worklist, use->fast_out(i));
2948     }
2949   }
2950 }
2951 
2952 // If we changed the receiver type to a call, we need to revisit the Catch node following the call. It's looking for a
2953 // non-null receiver to know when to enable the regular fall-through path in addition to the NullPtrException path.
2954 // Same is true if the type of a ValidLengthTest input to an AllocateArrayNode changes.

3026       continue;
3027     }
3028 
3029     Node* m = addI->in(1);
3030     if (m == andI->in(1) || m == andI->in(2)) {
3031       // Is "m" shared? Matched (1b) and thus we revisit Bool.
3032       push_if_not_bottom_type(worklist, bol);
3033     }
3034   }
3035 }
3036 
3037 // If n is used in a counted loop exit condition, then the type of the counted loop's Phi depends on the type of 'n'.
3038 // Seem PhiNode::Value().
3039 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
3040   uint use_op = use->Opcode();
3041   if (use_op == Op_CmpI || use_op == Op_CmpL) {
3042     PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
3043     if (phi != nullptr) {
3044       worklist.push(phi);
3045     }
3046   }
3047 }
3048 
3049 void PhaseCCP::push_cast(Unique_Node_List& worklist, const Node* use) {
3050   uint use_op = use->Opcode();
3051   if (use_op == Op_CastP2X) {
3052     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
3053       Node* u = use->fast_out(i2);
3054       if (u->Opcode() == Op_AndX) {
3055         worklist.push(u);
3056       }
3057     }
3058   }
3059 }
3060 
3061 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
3062 // See LoadNode::Value().
3063 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
3064   BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
3065   bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
3066 
3067   if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
3068     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
3069       Node* loadp = use->fast_out(i);
3070       const Type* ut = loadp->bottom_type();
3071       if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
3072         if (has_load_barrier_nodes) {
3073           // Search for load barriers behind the load
3074           push_load_barrier(worklist, barrier_set, loadp);
3075         }
3076         worklist.push(loadp);
3077       }
< prev index next >