221 // likely 2 or more) will promptly constant fold away.
222 PhaseGVN *phase = igvn;
223
224 // Make a region merging constants and a region merging the rest
225 uint req_c = 0;
226 Node* predicate_proj = NULL;
227 for (uint ii = 1; ii < r->req(); ii++) {
228 if (phi->in(ii) == con1) {
229 req_c++;
230 }
231 Node* proj = PhaseIdealLoop::find_predicate(r->in(ii));
232 if (proj != NULL) {
233 assert(predicate_proj == NULL, "only one predicate entry expected");
234 predicate_proj = proj;
235 }
236 }
237 Node* predicate_c = NULL;
238 Node* predicate_x = NULL;
239 bool counted_loop = r->is_CountedLoop();
240
241 Node *region_c = new (igvn->C) RegionNode(req_c + 1);
242 Node *phi_c = con1;
243 uint len = r->req();
244 Node *region_x = new (igvn->C) RegionNode(len - req_c);
245 Node *phi_x = PhiNode::make_blank(region_x, phi);
246 for (uint i = 1, i_c = 1, i_x = 1; i < len; i++) {
247 if (phi->in(i) == con1) {
248 region_c->init_req( i_c++, r ->in(i) );
249 if (r->in(i) == predicate_proj)
250 predicate_c = predicate_proj;
251 } else {
252 region_x->init_req( i_x, r ->in(i) );
253 phi_x ->init_req( i_x++, phi->in(i) );
254 if (r->in(i) == predicate_proj)
255 predicate_x = predicate_proj;
256 }
257 }
258 if (predicate_c != NULL && (req_c > 1)) {
259 assert(predicate_x == NULL, "only one predicate entry expected");
260 predicate_c = NULL; // Do not clone predicate below merge point
261 }
262 if (predicate_x != NULL && ((len - req_c) > 2)) {
263 assert(predicate_c == NULL, "only one predicate entry expected");
264 predicate_x = NULL; // Do not clone predicate below merge point
265 }
266
267 // Register the new RegionNodes but do not transform them. Cannot
268 // transform until the entire Region/Phi conglomerate has been hacked
269 // as a single huge transform.
270 igvn->register_new_node_with_optimizer( region_c );
271 igvn->register_new_node_with_optimizer( region_x );
272 // Prevent the untimely death of phi_x. Currently he has no uses. He is
273 // about to get one. If this only use goes away, then phi_x will look dead.
274 // However, he will be picking up some more uses down below.
275 Node *hook = new (igvn->C) Node(4);
276 hook->init_req(0, phi_x);
277 hook->init_req(1, phi_c);
278 phi_x = phase->transform( phi_x );
279
280 // Make the compare
281 Node *cmp_c = phase->makecon(t);
282 Node *cmp_x = cmp->clone();
283 cmp_x->set_req(1,phi_x);
284 cmp_x->set_req(2,con2);
285 cmp_x = phase->transform(cmp_x);
286 // Make the bool
287 Node *b_c = phase->transform(new (igvn->C) BoolNode(cmp_c,b->_test._test));
288 Node *b_x = phase->transform(new (igvn->C) BoolNode(cmp_x,b->_test._test));
289 // Make the IfNode
290 IfNode *iff_c = new (igvn->C) IfNode(region_c,b_c,iff->_prob,iff->_fcnt);
291 igvn->set_type_bottom(iff_c);
292 igvn->_worklist.push(iff_c);
293 hook->init_req(2, iff_c);
294
295 IfNode *iff_x = new (igvn->C) IfNode(region_x,b_x,iff->_prob, iff->_fcnt);
296 igvn->set_type_bottom(iff_x);
297 igvn->_worklist.push(iff_x);
298 hook->init_req(3, iff_x);
299
300 // Make the true/false arms
301 Node *iff_c_t = phase->transform(new (igvn->C) IfTrueNode (iff_c));
302 Node *iff_c_f = phase->transform(new (igvn->C) IfFalseNode(iff_c));
303 if (predicate_c != NULL) {
304 assert(predicate_x == NULL, "only one predicate entry expected");
305 // Clone loop predicates to each path
306 iff_c_t = igvn->clone_loop_predicates(predicate_c, iff_c_t, !counted_loop);
307 iff_c_f = igvn->clone_loop_predicates(predicate_c, iff_c_f, !counted_loop);
308 }
309 Node *iff_x_t = phase->transform(new (igvn->C) IfTrueNode (iff_x));
310 Node *iff_x_f = phase->transform(new (igvn->C) IfFalseNode(iff_x));
311 if (predicate_x != NULL) {
312 assert(predicate_c == NULL, "only one predicate entry expected");
313 // Clone loop predicates to each path
314 iff_x_t = igvn->clone_loop_predicates(predicate_x, iff_x_t, !counted_loop);
315 iff_x_f = igvn->clone_loop_predicates(predicate_x, iff_x_f, !counted_loop);
316 }
317
318 // Merge the TRUE paths
319 Node *region_s = new (igvn->C) RegionNode(3);
320 igvn->_worklist.push(region_s);
321 region_s->init_req(1, iff_c_t);
322 region_s->init_req(2, iff_x_t);
323 igvn->register_new_node_with_optimizer( region_s );
324
325 // Merge the FALSE paths
326 Node *region_f = new (igvn->C) RegionNode(3);
327 igvn->_worklist.push(region_f);
328 region_f->init_req(1, iff_c_f);
329 region_f->init_req(2, iff_x_f);
330 igvn->register_new_node_with_optimizer( region_f );
331
332 igvn->hash_delete(cmp);// Remove soon-to-be-dead node from hash table.
333 cmp->set_req(1,NULL); // Whack the inputs to cmp because it will be dead
334 cmp->set_req(2,NULL);
335 // Check for all uses of the Phi and give them a new home.
336 // The 'cmp' got cloned, but CastPP/IIs need to be moved.
337 Node *phi_s = NULL; // do not construct unless needed
338 Node *phi_f = NULL; // do not construct unless needed
339 for (DUIterator_Last i2min, i2 = phi->last_outs(i2min); i2 >= i2min; --i2) {
340 Node* v = phi->last_out(i2);// User of the phi
341 igvn->rehash_node_delayed(v); // Have to fixup other Phi users
342 uint vop = v->Opcode();
343 Node *proj = NULL;
344 if( vop == Op_Phi ) { // Remote merge point
345 Node *r = v->in(0);
346 for (uint i3 = 1; i3 < r->req(); i3++)
421 // Force the original merge dead
422 igvn->hash_delete(r);
423 // First, remove region's dead users.
424 for (DUIterator_Last lmin, l = r->last_outs(lmin); l >= lmin;) {
425 Node* u = r->last_out(l);
426 if( u == r ) {
427 r->set_req(0, NULL);
428 } else {
429 assert(u->outcnt() == 0, "only dead users");
430 igvn->remove_dead_node(u);
431 }
432 l -= 1;
433 }
434 igvn->remove_dead_node(r);
435
436 // Now remove the bogus extra edges used to keep things alive
437 igvn->remove_dead_node( hook );
438
439 // Must return either the original node (now dead) or a new node
440 // (Do not return a top here, since that would break the uniqueness of top.)
441 return new (igvn->C) ConINode(TypeInt::ZERO);
442 }
443
444 //------------------------------is_range_check---------------------------------
445 // Return 0 if not a range check. Return 1 if a range check and set index and
446 // offset. Return 2 if we had to negate the test. Index is NULL if the check
447 // is versus a constant.
448 int IfNode::is_range_check(Node* &range, Node* &index, jint &offset) {
449 Node* b = in(1);
450 if (b == NULL || !b->is_Bool()) return 0;
451 BoolNode* bn = b->as_Bool();
452 Node* cmp = bn->in(1);
453 if (cmp == NULL) return 0;
454 if (cmp->Opcode() != Op_CmpU) return 0;
455
456 Node* l = cmp->in(1);
457 Node* r = cmp->in(2);
458 int flip_test = 1;
459 if (bn->_test._test == BoolTest::le) {
460 l = cmp->in(2);
461 r = cmp->in(1);
524 return flip_test;
525 }
526
527 //------------------------------adjust_check-----------------------------------
528 // Adjust (widen) a prior range check
529 static void adjust_check(Node* proj, Node* range, Node* index,
530 int flip, jint off_lo, PhaseIterGVN* igvn) {
531 PhaseGVN *gvn = igvn;
532 // Break apart the old check
533 Node *iff = proj->in(0);
534 Node *bol = iff->in(1);
535 if( bol->is_top() ) return; // In case a partially dead range check appears
536 // bail (or bomb[ASSERT/DEBUG]) if NOT projection-->IfNode-->BoolNode
537 DEBUG_ONLY( if( !bol->is_Bool() ) { proj->dump(3); fatal("Expect projection-->IfNode-->BoolNode"); } )
538 if( !bol->is_Bool() ) return;
539
540 Node *cmp = bol->in(1);
541 // Compute a new check
542 Node *new_add = gvn->intcon(off_lo);
543 if( index ) {
544 new_add = off_lo ? gvn->transform(new (gvn->C) AddINode( index, new_add )) : index;
545 }
546 Node *new_cmp = (flip == 1)
547 ? new (gvn->C) CmpUNode( new_add, range )
548 : new (gvn->C) CmpUNode( range, new_add );
549 new_cmp = gvn->transform(new_cmp);
550 // See if no need to adjust the existing check
551 if( new_cmp == cmp ) return;
552 // Else, adjust existing check
553 Node *new_bol = gvn->transform( new (gvn->C) BoolNode( new_cmp, bol->as_Bool()->_test._test ) );
554 igvn->rehash_node_delayed( iff );
555 iff->set_req_X( 1, new_bol, igvn );
556 }
557
558 //------------------------------up_one_dom-------------------------------------
559 // Walk up the dominator tree one step. Return NULL at root or true
560 // complex merges. Skips through small diamonds.
561 Node* IfNode::up_one_dom(Node *curr, bool linear_only) {
562 Node *dom = curr->in(0);
563 if( !dom ) // Found a Region degraded to a copy?
564 return curr->nonnull_req(); // Skip thru it
565
566 if( curr != dom ) // Normal walk up one step?
567 return dom;
568
569 // Use linear_only if we are still parsing, since we cannot
570 // trust the regions to be fully filled in.
571 if (linear_only)
572 return NULL;
573
711 if (success != NULL && fail != NULL && !region->has_phi()) {
712 int lo = dom_iff->in(1)->in(1)->in(2)->get_int();
713 BoolNode* dom_bool = dom_iff->in(1)->as_Bool();
714 Node* dom_cmp = dom_bool->in(1);
715 const TypeInt* failtype = filtered_int_type(phase, n, ctrl);
716 if (failtype != NULL) {
717 const TypeInt* type2 = filtered_int_type(phase, n, fail);
718 if (type2 != NULL) {
719 failtype = failtype->join(type2)->is_int();
720 } else {
721 failtype = NULL;
722 }
723 }
724
725 if (failtype != NULL &&
726 dom_bool->_test._test != BoolTest::ne && dom_bool->_test._test != BoolTest::eq) {
727 int bound = failtype->_hi - failtype->_lo + 1;
728 if (failtype->_hi != max_jint && failtype->_lo != min_jint && bound > 1) {
729 // Merge the two compares into a single unsigned compare by building (CmpU (n - lo) hi)
730 BoolTest::mask cond = fail->as_Proj()->_con ? BoolTest::lt : BoolTest::ge;
731 Node* adjusted = phase->transform(new (phase->C) SubINode(n, phase->intcon(failtype->_lo)));
732 Node* newcmp = phase->transform(new (phase->C) CmpUNode(adjusted, phase->intcon(bound)));
733 Node* newbool = phase->transform(new (phase->C) BoolNode(newcmp, cond));
734 phase->is_IterGVN()->replace_input_of(dom_iff, 1, phase->intcon(ctrl->as_Proj()->_con));
735 phase->hash_delete(this);
736 set_req(1, newbool);
737 return this;
738 }
739 if (failtype->_lo > failtype->_hi) {
740 // previous if determines the result of this if so
741 // replace Bool with constant
742 phase->hash_delete(this);
743 set_req(1, phase->intcon(success->as_Proj()->_con));
744 return this;
745 }
746 }
747 }
748 }
749 }
750 }
751 return NULL;
752 }
753
986 } // End of Else scan for an equivalent test
987
988 // Hit! Remove this IF
989 #ifndef PRODUCT
990 if( TraceIterativeGVN ) {
991 tty->print(" Removing IfNode: "); this->dump();
992 }
993 if( VerifyOpto && !phase->allow_progress() ) {
994 // Found an equivalent dominating test,
995 // we can not guarantee reaching a fix-point for these during iterativeGVN
996 // since intervening nodes may not change.
997 return NULL;
998 }
999 #endif
1000
1001 // Replace dominated IfNode
1002 dominated_by( prev_dom, igvn );
1003
1004 // Must return either the original node (now dead) or a new node
1005 // (Do not return a top here, since that would break the uniqueness of top.)
1006 return new (phase->C) ConINode(TypeInt::ZERO);
1007 }
1008
1009 //------------------------------dominated_by-----------------------------------
1010 void IfNode::dominated_by( Node *prev_dom, PhaseIterGVN *igvn ) {
1011 igvn->hash_delete(this); // Remove self to prevent spurious V-N
1012 Node *idom = in(0);
1013 // Need opcode to decide which way 'this' test goes
1014 int prev_op = prev_dom->Opcode();
1015 Node *top = igvn->C->top(); // Shortcut to top
1016
1017 // Loop predicates may have depending checks which should not
1018 // be skipped. For example, range check predicate has two checks
1019 // for lower and upper bounds.
1020 ProjNode* unc_proj = proj_out(1 - prev_dom->as_Proj()->_con)->as_Proj();
1021 if (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate))
1022 prev_dom = idom;
1023
1024 // Now walk the current IfNode's projections.
1025 // Loop ends when 'this' has no more uses.
1026 for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
1082 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1083 assert(iff->in(0) != NULL, "If must be live");
1084
1085 if (iff->outcnt() != 2) return NULL; // Malformed projections.
1086 Node* old_if_f = iff->proj_out(false);
1087 Node* old_if_t = iff->proj_out(true);
1088
1089 // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1090 // whether they are testing a 'gt' or 'lt' condition. The 'gt' condition
1091 // happens in count-down loops
1092 if (iff->is_CountedLoopEnd()) return NULL;
1093 if (!iff->in(1)->is_Bool()) return NULL; // Happens for partially optimized IF tests
1094 BoolNode *b = iff->in(1)->as_Bool();
1095 BoolTest bt = b->_test;
1096 // Test already in good order?
1097 if( bt.is_canonical() )
1098 return NULL;
1099
1100 // Flip test to be canonical. Requires flipping the IfFalse/IfTrue and
1101 // cloning the IfNode.
1102 Node* new_b = phase->transform( new (phase->C) BoolNode(b->in(1), bt.negate()) );
1103 if( !new_b->is_Bool() ) return NULL;
1104 b = new_b->as_Bool();
1105
1106 PhaseIterGVN *igvn = phase->is_IterGVN();
1107 assert( igvn, "Test is not canonical in parser?" );
1108
1109 // The IF node never really changes, but it needs to be cloned
1110 iff = new (phase->C) IfNode( iff->in(0), b, 1.0-iff->_prob, iff->_fcnt);
1111
1112 Node *prior = igvn->hash_find_insert(iff);
1113 if( prior ) {
1114 igvn->remove_dead_node(iff);
1115 iff = (IfNode*)prior;
1116 } else {
1117 // Cannot call transform on it just yet
1118 igvn->set_type_bottom(iff);
1119 }
1120 igvn->_worklist.push(iff);
1121
1122 // Now handle projections. Cloning not required.
1123 Node* new_if_f = (Node*)(new (phase->C) IfFalseNode( iff ));
1124 Node* new_if_t = (Node*)(new (phase->C) IfTrueNode ( iff ));
1125
1126 igvn->register_new_node_with_optimizer(new_if_f);
1127 igvn->register_new_node_with_optimizer(new_if_t);
1128 // Flip test, so flip trailing control
1129 igvn->replace_node(old_if_f, new_if_t);
1130 igvn->replace_node(old_if_t, new_if_f);
1131
1132 // Progress
1133 return iff;
1134 }
1135
1136 //------------------------------Identity---------------------------------------
1137 // If the test is constant & we match, then we are the input Control
1138 Node *IfFalseNode::Identity( PhaseTransform *phase ) {
1139 // Can only optimize if cannot go the other way
1140 const TypeTuple *t = phase->type(in(0))->is_tuple();
1141 return ( t == TypeTuple::IFNEITHER || t == TypeTuple::IFFALSE )
1142 ? in(0)->in(0) // IfNode control
1143 : this; // no progress
1144 }
|
221 // likely 2 or more) will promptly constant fold away.
222 PhaseGVN *phase = igvn;
223
224 // Make a region merging constants and a region merging the rest
225 uint req_c = 0;
226 Node* predicate_proj = NULL;
227 for (uint ii = 1; ii < r->req(); ii++) {
228 if (phi->in(ii) == con1) {
229 req_c++;
230 }
231 Node* proj = PhaseIdealLoop::find_predicate(r->in(ii));
232 if (proj != NULL) {
233 assert(predicate_proj == NULL, "only one predicate entry expected");
234 predicate_proj = proj;
235 }
236 }
237 Node* predicate_c = NULL;
238 Node* predicate_x = NULL;
239 bool counted_loop = r->is_CountedLoop();
240
241 Node *region_c = new RegionNode(req_c + 1);
242 Node *phi_c = con1;
243 uint len = r->req();
244 Node *region_x = new RegionNode(len - req_c);
245 Node *phi_x = PhiNode::make_blank(region_x, phi);
246 for (uint i = 1, i_c = 1, i_x = 1; i < len; i++) {
247 if (phi->in(i) == con1) {
248 region_c->init_req( i_c++, r ->in(i) );
249 if (r->in(i) == predicate_proj)
250 predicate_c = predicate_proj;
251 } else {
252 region_x->init_req( i_x, r ->in(i) );
253 phi_x ->init_req( i_x++, phi->in(i) );
254 if (r->in(i) == predicate_proj)
255 predicate_x = predicate_proj;
256 }
257 }
258 if (predicate_c != NULL && (req_c > 1)) {
259 assert(predicate_x == NULL, "only one predicate entry expected");
260 predicate_c = NULL; // Do not clone predicate below merge point
261 }
262 if (predicate_x != NULL && ((len - req_c) > 2)) {
263 assert(predicate_c == NULL, "only one predicate entry expected");
264 predicate_x = NULL; // Do not clone predicate below merge point
265 }
266
267 // Register the new RegionNodes but do not transform them. Cannot
268 // transform until the entire Region/Phi conglomerate has been hacked
269 // as a single huge transform.
270 igvn->register_new_node_with_optimizer( region_c );
271 igvn->register_new_node_with_optimizer( region_x );
272 // Prevent the untimely death of phi_x. Currently he has no uses. He is
273 // about to get one. If this only use goes away, then phi_x will look dead.
274 // However, he will be picking up some more uses down below.
275 Node *hook = new Node(4);
276 hook->init_req(0, phi_x);
277 hook->init_req(1, phi_c);
278 phi_x = phase->transform( phi_x );
279
280 // Make the compare
281 Node *cmp_c = phase->makecon(t);
282 Node *cmp_x = cmp->clone();
283 cmp_x->set_req(1,phi_x);
284 cmp_x->set_req(2,con2);
285 cmp_x = phase->transform(cmp_x);
286 // Make the bool
287 Node *b_c = phase->transform(new BoolNode(cmp_c,b->_test._test));
288 Node *b_x = phase->transform(new BoolNode(cmp_x,b->_test._test));
289 // Make the IfNode
290 IfNode *iff_c = new IfNode(region_c,b_c,iff->_prob,iff->_fcnt);
291 igvn->set_type_bottom(iff_c);
292 igvn->_worklist.push(iff_c);
293 hook->init_req(2, iff_c);
294
295 IfNode *iff_x = new IfNode(region_x,b_x,iff->_prob, iff->_fcnt);
296 igvn->set_type_bottom(iff_x);
297 igvn->_worklist.push(iff_x);
298 hook->init_req(3, iff_x);
299
300 // Make the true/false arms
301 Node *iff_c_t = phase->transform(new IfTrueNode (iff_c));
302 Node *iff_c_f = phase->transform(new IfFalseNode(iff_c));
303 if (predicate_c != NULL) {
304 assert(predicate_x == NULL, "only one predicate entry expected");
305 // Clone loop predicates to each path
306 iff_c_t = igvn->clone_loop_predicates(predicate_c, iff_c_t, !counted_loop);
307 iff_c_f = igvn->clone_loop_predicates(predicate_c, iff_c_f, !counted_loop);
308 }
309 Node *iff_x_t = phase->transform(new IfTrueNode (iff_x));
310 Node *iff_x_f = phase->transform(new IfFalseNode(iff_x));
311 if (predicate_x != NULL) {
312 assert(predicate_c == NULL, "only one predicate entry expected");
313 // Clone loop predicates to each path
314 iff_x_t = igvn->clone_loop_predicates(predicate_x, iff_x_t, !counted_loop);
315 iff_x_f = igvn->clone_loop_predicates(predicate_x, iff_x_f, !counted_loop);
316 }
317
318 // Merge the TRUE paths
319 Node *region_s = new RegionNode(3);
320 igvn->_worklist.push(region_s);
321 region_s->init_req(1, iff_c_t);
322 region_s->init_req(2, iff_x_t);
323 igvn->register_new_node_with_optimizer( region_s );
324
325 // Merge the FALSE paths
326 Node *region_f = new RegionNode(3);
327 igvn->_worklist.push(region_f);
328 region_f->init_req(1, iff_c_f);
329 region_f->init_req(2, iff_x_f);
330 igvn->register_new_node_with_optimizer( region_f );
331
332 igvn->hash_delete(cmp);// Remove soon-to-be-dead node from hash table.
333 cmp->set_req(1,NULL); // Whack the inputs to cmp because it will be dead
334 cmp->set_req(2,NULL);
335 // Check for all uses of the Phi and give them a new home.
336 // The 'cmp' got cloned, but CastPP/IIs need to be moved.
337 Node *phi_s = NULL; // do not construct unless needed
338 Node *phi_f = NULL; // do not construct unless needed
339 for (DUIterator_Last i2min, i2 = phi->last_outs(i2min); i2 >= i2min; --i2) {
340 Node* v = phi->last_out(i2);// User of the phi
341 igvn->rehash_node_delayed(v); // Have to fixup other Phi users
342 uint vop = v->Opcode();
343 Node *proj = NULL;
344 if( vop == Op_Phi ) { // Remote merge point
345 Node *r = v->in(0);
346 for (uint i3 = 1; i3 < r->req(); i3++)
421 // Force the original merge dead
422 igvn->hash_delete(r);
423 // First, remove region's dead users.
424 for (DUIterator_Last lmin, l = r->last_outs(lmin); l >= lmin;) {
425 Node* u = r->last_out(l);
426 if( u == r ) {
427 r->set_req(0, NULL);
428 } else {
429 assert(u->outcnt() == 0, "only dead users");
430 igvn->remove_dead_node(u);
431 }
432 l -= 1;
433 }
434 igvn->remove_dead_node(r);
435
436 // Now remove the bogus extra edges used to keep things alive
437 igvn->remove_dead_node( hook );
438
439 // Must return either the original node (now dead) or a new node
440 // (Do not return a top here, since that would break the uniqueness of top.)
441 return new ConINode(TypeInt::ZERO);
442 }
443
444 //------------------------------is_range_check---------------------------------
445 // Return 0 if not a range check. Return 1 if a range check and set index and
446 // offset. Return 2 if we had to negate the test. Index is NULL if the check
447 // is versus a constant.
448 int IfNode::is_range_check(Node* &range, Node* &index, jint &offset) {
449 Node* b = in(1);
450 if (b == NULL || !b->is_Bool()) return 0;
451 BoolNode* bn = b->as_Bool();
452 Node* cmp = bn->in(1);
453 if (cmp == NULL) return 0;
454 if (cmp->Opcode() != Op_CmpU) return 0;
455
456 Node* l = cmp->in(1);
457 Node* r = cmp->in(2);
458 int flip_test = 1;
459 if (bn->_test._test == BoolTest::le) {
460 l = cmp->in(2);
461 r = cmp->in(1);
524 return flip_test;
525 }
526
527 //------------------------------adjust_check-----------------------------------
528 // Adjust (widen) a prior range check
529 static void adjust_check(Node* proj, Node* range, Node* index,
530 int flip, jint off_lo, PhaseIterGVN* igvn) {
531 PhaseGVN *gvn = igvn;
532 // Break apart the old check
533 Node *iff = proj->in(0);
534 Node *bol = iff->in(1);
535 if( bol->is_top() ) return; // In case a partially dead range check appears
536 // bail (or bomb[ASSERT/DEBUG]) if NOT projection-->IfNode-->BoolNode
537 DEBUG_ONLY( if( !bol->is_Bool() ) { proj->dump(3); fatal("Expect projection-->IfNode-->BoolNode"); } )
538 if( !bol->is_Bool() ) return;
539
540 Node *cmp = bol->in(1);
541 // Compute a new check
542 Node *new_add = gvn->intcon(off_lo);
543 if( index ) {
544 new_add = off_lo ? gvn->transform(new AddINode( index, new_add )) : index;
545 }
546 Node *new_cmp = (flip == 1)
547 ? new CmpUNode( new_add, range )
548 : new CmpUNode( range, new_add );
549 new_cmp = gvn->transform(new_cmp);
550 // See if no need to adjust the existing check
551 if( new_cmp == cmp ) return;
552 // Else, adjust existing check
553 Node *new_bol = gvn->transform( new BoolNode( new_cmp, bol->as_Bool()->_test._test ) );
554 igvn->rehash_node_delayed( iff );
555 iff->set_req_X( 1, new_bol, igvn );
556 }
557
558 //------------------------------up_one_dom-------------------------------------
559 // Walk up the dominator tree one step. Return NULL at root or true
560 // complex merges. Skips through small diamonds.
561 Node* IfNode::up_one_dom(Node *curr, bool linear_only) {
562 Node *dom = curr->in(0);
563 if( !dom ) // Found a Region degraded to a copy?
564 return curr->nonnull_req(); // Skip thru it
565
566 if( curr != dom ) // Normal walk up one step?
567 return dom;
568
569 // Use linear_only if we are still parsing, since we cannot
570 // trust the regions to be fully filled in.
571 if (linear_only)
572 return NULL;
573
711 if (success != NULL && fail != NULL && !region->has_phi()) {
712 int lo = dom_iff->in(1)->in(1)->in(2)->get_int();
713 BoolNode* dom_bool = dom_iff->in(1)->as_Bool();
714 Node* dom_cmp = dom_bool->in(1);
715 const TypeInt* failtype = filtered_int_type(phase, n, ctrl);
716 if (failtype != NULL) {
717 const TypeInt* type2 = filtered_int_type(phase, n, fail);
718 if (type2 != NULL) {
719 failtype = failtype->join(type2)->is_int();
720 } else {
721 failtype = NULL;
722 }
723 }
724
725 if (failtype != NULL &&
726 dom_bool->_test._test != BoolTest::ne && dom_bool->_test._test != BoolTest::eq) {
727 int bound = failtype->_hi - failtype->_lo + 1;
728 if (failtype->_hi != max_jint && failtype->_lo != min_jint && bound > 1) {
729 // Merge the two compares into a single unsigned compare by building (CmpU (n - lo) hi)
730 BoolTest::mask cond = fail->as_Proj()->_con ? BoolTest::lt : BoolTest::ge;
731 Node* adjusted = phase->transform(new SubINode(n, phase->intcon(failtype->_lo)));
732 Node* newcmp = phase->transform(new CmpUNode(adjusted, phase->intcon(bound)));
733 Node* newbool = phase->transform(new BoolNode(newcmp, cond));
734 phase->is_IterGVN()->replace_input_of(dom_iff, 1, phase->intcon(ctrl->as_Proj()->_con));
735 phase->hash_delete(this);
736 set_req(1, newbool);
737 return this;
738 }
739 if (failtype->_lo > failtype->_hi) {
740 // previous if determines the result of this if so
741 // replace Bool with constant
742 phase->hash_delete(this);
743 set_req(1, phase->intcon(success->as_Proj()->_con));
744 return this;
745 }
746 }
747 }
748 }
749 }
750 }
751 return NULL;
752 }
753
986 } // End of Else scan for an equivalent test
987
988 // Hit! Remove this IF
989 #ifndef PRODUCT
990 if( TraceIterativeGVN ) {
991 tty->print(" Removing IfNode: "); this->dump();
992 }
993 if( VerifyOpto && !phase->allow_progress() ) {
994 // Found an equivalent dominating test,
995 // we can not guarantee reaching a fix-point for these during iterativeGVN
996 // since intervening nodes may not change.
997 return NULL;
998 }
999 #endif
1000
1001 // Replace dominated IfNode
1002 dominated_by( prev_dom, igvn );
1003
1004 // Must return either the original node (now dead) or a new node
1005 // (Do not return a top here, since that would break the uniqueness of top.)
1006 return new ConINode(TypeInt::ZERO);
1007 }
1008
1009 //------------------------------dominated_by-----------------------------------
1010 void IfNode::dominated_by( Node *prev_dom, PhaseIterGVN *igvn ) {
1011 igvn->hash_delete(this); // Remove self to prevent spurious V-N
1012 Node *idom = in(0);
1013 // Need opcode to decide which way 'this' test goes
1014 int prev_op = prev_dom->Opcode();
1015 Node *top = igvn->C->top(); // Shortcut to top
1016
1017 // Loop predicates may have depending checks which should not
1018 // be skipped. For example, range check predicate has two checks
1019 // for lower and upper bounds.
1020 ProjNode* unc_proj = proj_out(1 - prev_dom->as_Proj()->_con)->as_Proj();
1021 if (unc_proj->is_uncommon_trap_proj(Deoptimization::Reason_predicate))
1022 prev_dom = idom;
1023
1024 // Now walk the current IfNode's projections.
1025 // Loop ends when 'this' has no more uses.
1026 for (DUIterator_Last imin, i = last_outs(imin); i >= imin; --i) {
1082 static IfNode* idealize_test(PhaseGVN* phase, IfNode* iff) {
1083 assert(iff->in(0) != NULL, "If must be live");
1084
1085 if (iff->outcnt() != 2) return NULL; // Malformed projections.
1086 Node* old_if_f = iff->proj_out(false);
1087 Node* old_if_t = iff->proj_out(true);
1088
1089 // CountedLoopEnds want the back-control test to be TRUE, irregardless of
1090 // whether they are testing a 'gt' or 'lt' condition. The 'gt' condition
1091 // happens in count-down loops
1092 if (iff->is_CountedLoopEnd()) return NULL;
1093 if (!iff->in(1)->is_Bool()) return NULL; // Happens for partially optimized IF tests
1094 BoolNode *b = iff->in(1)->as_Bool();
1095 BoolTest bt = b->_test;
1096 // Test already in good order?
1097 if( bt.is_canonical() )
1098 return NULL;
1099
1100 // Flip test to be canonical. Requires flipping the IfFalse/IfTrue and
1101 // cloning the IfNode.
1102 Node* new_b = phase->transform( new BoolNode(b->in(1), bt.negate()) );
1103 if( !new_b->is_Bool() ) return NULL;
1104 b = new_b->as_Bool();
1105
1106 PhaseIterGVN *igvn = phase->is_IterGVN();
1107 assert( igvn, "Test is not canonical in parser?" );
1108
1109 // The IF node never really changes, but it needs to be cloned
1110 iff = new IfNode( iff->in(0), b, 1.0-iff->_prob, iff->_fcnt);
1111
1112 Node *prior = igvn->hash_find_insert(iff);
1113 if( prior ) {
1114 igvn->remove_dead_node(iff);
1115 iff = (IfNode*)prior;
1116 } else {
1117 // Cannot call transform on it just yet
1118 igvn->set_type_bottom(iff);
1119 }
1120 igvn->_worklist.push(iff);
1121
1122 // Now handle projections. Cloning not required.
1123 Node* new_if_f = (Node*)(new IfFalseNode( iff ));
1124 Node* new_if_t = (Node*)(new IfTrueNode ( iff ));
1125
1126 igvn->register_new_node_with_optimizer(new_if_f);
1127 igvn->register_new_node_with_optimizer(new_if_t);
1128 // Flip test, so flip trailing control
1129 igvn->replace_node(old_if_f, new_if_t);
1130 igvn->replace_node(old_if_t, new_if_f);
1131
1132 // Progress
1133 return iff;
1134 }
1135
1136 //------------------------------Identity---------------------------------------
1137 // If the test is constant & we match, then we are the input Control
1138 Node *IfFalseNode::Identity( PhaseTransform *phase ) {
1139 // Can only optimize if cannot go the other way
1140 const TypeTuple *t = phase->type(in(0))->is_tuple();
1141 return ( t == TypeTuple::IFNEITHER || t == TypeTuple::IFFALSE )
1142 ? in(0)->in(0) // IfNode control
1143 : this; // no progress
1144 }
|