120 for (int i = 0; i < _replaced_nodes->length(); i++) {
121 ReplacedNode replaced = _replaced_nodes->at(i);
122 Node* initial = replaced.initial();
123 Node* improved = replaced.improved();
124 assert (ctl != nullptr && !ctl->is_top(), "replaced node should have actual control");
125
126 if (initial->outcnt() == 0) {
127 continue;
128 }
129
130 // Find uses of initial that are dominated by ctl so, initial can be replaced by improved.
131 // Proving domination here is not straightforward. To do so, we follow uses of initial, and uses of uses until we
132 // encounter a node which is a control node or is pinned at some control. Then, we try to prove this control is
133 // dominated by ctl. If that's the case, it's legal to replace initial by improved but for this chain of uses only.
134 // It may not be the case for some other chain of uses, so we clone that chain and perform the replacement only for
135 // these uses.
136 assert(stack.is_empty(), "");
137 stack.push(initial, 1);
138 Node* use = initial->raw_out(0);
139 stack.push(use, 0);
140
141 while (!stack.is_empty()) {
142 assert(stack.size() > 1, "at least initial + one use");
143 Node* n = stack.node();
144
145 uint current_size = stack.size();
146
147 if (seen.test_set(n->_idx)) {
148 if (to_fix.member(n)) {
149 collect_nodes_to_clone(stack, to_fix);
150 }
151 } else if (n->outcnt() != 0 && n != improved) {
152 if (n->is_Phi()) {
153 Node* region = n->in(0);
154 if (n->req() == region->req()) { // ignore dead phis
155 Node* prev = stack.node_at(stack.size() - 2);
156 for (uint j = 1; j < region->req(); ++j) {
157 if (n->in(j) == prev) {
158 Node* in = region->in(j);
159 if (in != nullptr && !in->is_top() && is_dominator(ctl, in)) {
160 valid_control.set(in->_idx);
|
120 for (int i = 0; i < _replaced_nodes->length(); i++) {
121 ReplacedNode replaced = _replaced_nodes->at(i);
122 Node* initial = replaced.initial();
123 Node* improved = replaced.improved();
124 assert (ctl != nullptr && !ctl->is_top(), "replaced node should have actual control");
125
126 if (initial->outcnt() == 0) {
127 continue;
128 }
129
130 // Find uses of initial that are dominated by ctl so, initial can be replaced by improved.
131 // Proving domination here is not straightforward. To do so, we follow uses of initial, and uses of uses until we
132 // encounter a node which is a control node or is pinned at some control. Then, we try to prove this control is
133 // dominated by ctl. If that's the case, it's legal to replace initial by improved but for this chain of uses only.
134 // It may not be the case for some other chain of uses, so we clone that chain and perform the replacement only for
135 // these uses.
136 assert(stack.is_empty(), "");
137 stack.push(initial, 1);
138 Node* use = initial->raw_out(0);
139 stack.push(use, 0);
140 while (!stack.is_empty()) {
141 assert(stack.size() > 1, "at least initial + one use");
142 Node* n = stack.node();
143
144 uint current_size = stack.size();
145
146 if (seen.test_set(n->_idx)) {
147 if (to_fix.member(n)) {
148 collect_nodes_to_clone(stack, to_fix);
149 }
150 } else if (n->outcnt() != 0 && n != improved) {
151 if (n->is_Phi()) {
152 Node* region = n->in(0);
153 if (n->req() == region->req()) { // ignore dead phis
154 Node* prev = stack.node_at(stack.size() - 2);
155 for (uint j = 1; j < region->req(); ++j) {
156 if (n->in(j) == prev) {
157 Node* in = region->in(j);
158 if (in != nullptr && !in->is_top() && is_dominator(ctl, in)) {
159 valid_control.set(in->_idx);
|