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