src/share/vm/opto/loopTransform.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/loopTransform.cpp

Print this page
rev 10175 : 8137049: Code quality: reducing an trivial integer loop does not produce an optimal code
Summary: canonicalized if shape not recognized by empty loop detection code
Reviewed-by:


2387   }
2388   assert(iv == cl->phi(), "Wrong phi" );
2389 #endif
2390 
2391   // main and post loops have explicitly created zero trip guard
2392   bool needs_guard = !cl->is_main_loop() && !cl->is_post_loop();
2393   if (needs_guard) {
2394     // Skip guard if values not overlap.
2395     const TypeInt* init_t = phase->_igvn.type(cl->init_trip())->is_int();
2396     const TypeInt* limit_t = phase->_igvn.type(cl->limit())->is_int();
2397     int  stride_con = cl->stride_con();
2398     if (stride_con > 0) {
2399       needs_guard = (init_t->_hi >= limit_t->_lo);
2400     } else {
2401       needs_guard = (init_t->_lo <= limit_t->_hi);
2402     }
2403   }
2404   if (needs_guard) {
2405     // Check for an obvious zero trip guard.
2406     Node* inctrl = PhaseIdealLoop::skip_loop_predicates(cl->in(LoopNode::EntryControl));
2407     if (inctrl->Opcode() == Op_IfTrue) {

2408       // The test should look like just the backedge of a CountedLoop
2409       Node* iff = inctrl->in(0);
2410       if (iff->is_If()) {
2411         Node* bol = iff->in(1);
2412         if (bol->is_Bool() && bol->as_Bool()->_test._test == cl->loopexit()->test_trip()) {






2413           Node* cmp = bol->in(1);
2414           if (cmp->is_Cmp() && cmp->in(1) == cl->init_trip() && cmp->in(2) == cl->limit()) {


2415             needs_guard = false;

2416           }
2417         }
2418       }
2419     }
2420   }
2421 
2422 #ifndef PRODUCT
2423   if (PrintOpto) {
2424     tty->print("Removing empty loop with%s zero trip guard", needs_guard ? "out" : "");
2425     this->dump_head();
2426   } else if (TraceLoopOpts) {
2427     tty->print("Empty with%s zero trip guard   ", needs_guard ? "out" : "");
2428     this->dump_head();
2429   }
2430 #endif
2431 
2432   if (needs_guard) {
2433     // Peel the loop to ensure there's a zero trip guard
2434     Node_List old_new;
2435     phase->do_peeling(this, old_new);




2387   }
2388   assert(iv == cl->phi(), "Wrong phi" );
2389 #endif
2390 
2391   // main and post loops have explicitly created zero trip guard
2392   bool needs_guard = !cl->is_main_loop() && !cl->is_post_loop();
2393   if (needs_guard) {
2394     // Skip guard if values not overlap.
2395     const TypeInt* init_t = phase->_igvn.type(cl->init_trip())->is_int();
2396     const TypeInt* limit_t = phase->_igvn.type(cl->limit())->is_int();
2397     int  stride_con = cl->stride_con();
2398     if (stride_con > 0) {
2399       needs_guard = (init_t->_hi >= limit_t->_lo);
2400     } else {
2401       needs_guard = (init_t->_lo <= limit_t->_hi);
2402     }
2403   }
2404   if (needs_guard) {
2405     // Check for an obvious zero trip guard.
2406     Node* inctrl = PhaseIdealLoop::skip_loop_predicates(cl->in(LoopNode::EntryControl));
2407     if (inctrl->Opcode() == Op_IfTrue || inctrl->Opcode() == Op_IfFalse) {
2408       bool maybe_swapped = (inctrl->Opcode() == Op_IfFalse);
2409       // The test should look like just the backedge of a CountedLoop
2410       Node* iff = inctrl->in(0);
2411       if (iff->is_If()) {
2412         Node* bol = iff->in(1);
2413         if (bol->is_Bool()) {
2414           BoolTest test = bol->as_Bool()->_test;
2415           if (maybe_swapped) {
2416             test._test = test.commute();
2417             test._test = test.negate();
2418           }
2419           if (test._test == cl->loopexit()->test_trip()) {
2420             Node* cmp = bol->in(1);
2421             int init_idx = maybe_swapped ? 2 : 1;
2422             int limit_idx = 3 - init_idx;
2423             if (cmp->is_Cmp() && cmp->in(init_idx) == cl->init_trip() && cmp->in(limit_idx) == cl->limit()) {
2424               needs_guard = false;
2425             }
2426           }
2427         }
2428       }
2429     }
2430   }
2431 
2432 #ifndef PRODUCT
2433   if (PrintOpto) {
2434     tty->print("Removing empty loop with%s zero trip guard", needs_guard ? "out" : "");
2435     this->dump_head();
2436   } else if (TraceLoopOpts) {
2437     tty->print("Empty with%s zero trip guard   ", needs_guard ? "out" : "");
2438     this->dump_head();
2439   }
2440 #endif
2441 
2442   if (needs_guard) {
2443     // Peel the loop to ensure there's a zero trip guard
2444     Node_List old_new;
2445     phase->do_peeling(this, old_new);


src/share/vm/opto/loopTransform.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File