< 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);

2619   // If the ValidLengthTest input changes then the fallthrough path out of the AllocateArray may have become dead.
2620   // CatchNode::Value() is responsible for killing that path. The CatchNode has to be explicitly enqueued for igvn
2621   // to guarantee the change is not missed.
2622   if (use_op == Op_AllocateArray && n == use->in(AllocateNode::ValidLengthTest)) {
2623     Node* p = use->as_AllocateArray()->proj_out_or_null(TypeFunc::Control);
2624     if (p != nullptr) {
2625       add_users_to_worklist0(p, worklist);
2626     }
2627   }
2628 
2629   if (use_op == Op_Initialize) {
2630     InitializeNode* init = use->as_Initialize();
2631     init->for_each_proj(enqueue_init_mem_projs, TypeFunc::Memory);
2632   }
2633   // Loading the java mirror from a Klass requires two loads and the type
2634   // of the mirror load depends on the type of 'n'. See LoadNode::Value().
2635   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
2636   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2637   bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
2638 








2639   if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
2640     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2641       Node* u = use->fast_out(i2);
2642       const Type* ut = u->bottom_type();
2643       if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
2644         if (has_load_barrier_nodes) {
2645           // Search for load barriers behind the load
2646           for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
2647             Node* b = u->fast_out(i3);
2648             if (bs->is_gc_barrier_node(b)) {
2649               worklist.push(b);
2650             }
2651           }
2652         }
2653         worklist.push(u);
2654       }
2655     }
2656   }










2657   if (use->Opcode() == Op_OpaqueZeroTripGuard) {
2658     assert(use->outcnt() <= 1, "OpaqueZeroTripGuard can't be shared");
2659     if (use->outcnt() == 1) {
2660       Node* cmp = use->unique_out();
2661       worklist.push(cmp);
2662     }
2663   }
2664 
2665   // From CastX2PNode::Ideal
2666   // CastX2P(AddX(x, y))
2667   // CastX2P(SubX(x, y))
2668   if (use->Opcode() == Op_AddX || use->Opcode() == Op_SubX) {
2669     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
2670       Node* u = use->fast_out(i2);
2671       if (u->Opcode() == Op_CastX2P) {
2672         worklist.push(u);
2673       }
2674     }
2675   }
2676 

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

2878   for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2879     Node* use = n->fast_out(i);
2880     push_if_not_bottom_type(worklist, use);
2881     push_more_uses(worklist, n, use);
2882   }
2883 }
2884 
2885 void PhaseCCP::push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const {
2886   if (n->bottom_type() != type(n)) {
2887     worklist.push(n);
2888   }
2889 }
2890 
2891 // For some nodes, we need to propagate the type change to grandchildren or even further down.
2892 // Add them back to the worklist.
2893 void PhaseCCP::push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const {
2894   push_phis(worklist, use);
2895   push_catch(worklist, use);
2896   push_cmpu(worklist, use);
2897   push_counted_loop_phi(worklist, parent, use);

2898   push_loadp(worklist, use);
2899   push_and(worklist, parent, use);
2900   push_cast_ii(worklist, parent, use);
2901   push_opaque_zero_trip_guard(worklist, use);
2902   push_bool_with_cmpu_and_mask(worklist, use);
2903 }
2904 
2905 
2906 // We must recheck Phis too if use is a Region.
2907 void PhaseCCP::push_phis(Unique_Node_List& worklist, const Node* use) const {
2908   if (use->is_Region()) {
2909     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
2910       push_if_not_bottom_type(worklist, use->fast_out(i));
2911     }
2912   }
2913 }
2914 
2915 // If we changed the receiver type to a call, we need to revisit the Catch node following the call. It's looking for a
2916 // non-null receiver to know when to enable the regular fall-through path in addition to the NullPtrException path.
2917 // Same is true if the type of a ValidLengthTest input to an AllocateArrayNode changes.

2989       continue;
2990     }
2991 
2992     Node* m = addI->in(1);
2993     if (m == andI->in(1) || m == andI->in(2)) {
2994       // Is "m" shared? Matched (1b) and thus we revisit Bool.
2995       push_if_not_bottom_type(worklist, bol);
2996     }
2997   }
2998 }
2999 
3000 // 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'.
3001 // Seem PhiNode::Value().
3002 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
3003   uint use_op = use->Opcode();
3004   if (use_op == Op_CmpI || use_op == Op_CmpL) {
3005     PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
3006     if (phi != nullptr) {
3007       worklist.push(phi);
3008     }












3009   }
3010 }
3011 
3012 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
3013 // See LoadNode::Value().
3014 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
3015   BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
3016   bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
3017 
3018   if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
3019     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
3020       Node* loadp = use->fast_out(i);
3021       const Type* ut = loadp->bottom_type();
3022       if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
3023         if (has_load_barrier_nodes) {
3024           // Search for load barriers behind the load
3025           push_load_barrier(worklist, barrier_set, loadp);
3026         }
3027         worklist.push(loadp);
3028       }

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);

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

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

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

3040       continue;
3041     }
3042 
3043     Node* m = addI->in(1);
3044     if (m == andI->in(1) || m == andI->in(2)) {
3045       // Is "m" shared? Matched (1b) and thus we revisit Bool.
3046       push_if_not_bottom_type(worklist, bol);
3047     }
3048   }
3049 }
3050 
3051 // 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'.
3052 // Seem PhiNode::Value().
3053 void PhaseCCP::push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use) {
3054   uint use_op = use->Opcode();
3055   if (use_op == Op_CmpI || use_op == Op_CmpL) {
3056     PhiNode* phi = countedloop_phi_from_cmp(use->as_Cmp(), parent);
3057     if (phi != nullptr) {
3058       worklist.push(phi);
3059     }
3060   }
3061 }
3062 
3063 void PhaseCCP::push_cast(Unique_Node_List& worklist, const Node* use) {
3064   uint use_op = use->Opcode();
3065   if (use_op == Op_CastP2X) {
3066     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
3067       Node* u = use->fast_out(i2);
3068       if (u->Opcode() == Op_AndX) {
3069         worklist.push(u);
3070       }
3071     }
3072   }
3073 }
3074 
3075 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
3076 // See LoadNode::Value().
3077 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
3078   BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
3079   bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
3080 
3081   if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
3082     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
3083       Node* loadp = use->fast_out(i);
3084       const Type* ut = loadp->bottom_type();
3085       if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
3086         if (has_load_barrier_nodes) {
3087           // Search for load barriers behind the load
3088           push_load_barrier(worklist, barrier_set, loadp);
3089         }
3090         worklist.push(loadp);
3091       }
< prev index next >