hotspot/src/share/vm/opto/loopTransform.cpp
changeset 46630 75aa3e39d02c
parent 44314 30ae899b9eca
child 46692 117b089cb1c3
equal deleted inserted replaced
46629:8eeacdc76bf2 46630:75aa3e39d02c
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   206 // (inv2 - x) + inv1  =>  ( inv1 + inv2) - x
   206 // (inv2 - x) + inv1  =>  ( inv1 + inv2) - x
   207 // (inv2 - x) - inv1  =>  (-inv1 + inv2) - x
   207 // (inv2 - x) - inv1  =>  (-inv1 + inv2) - x
   208 // inv1 - (x + inv2)  =>  ( inv1 - inv2) - x
   208 // inv1 - (x + inv2)  =>  ( inv1 - inv2) - x
   209 //
   209 //
   210 Node* IdealLoopTree::reassociate_add_sub(Node* n1, PhaseIdealLoop *phase) {
   210 Node* IdealLoopTree::reassociate_add_sub(Node* n1, PhaseIdealLoop *phase) {
   211   if (!n1->is_Add() && !n1->is_Sub() || n1->outcnt() == 0) return NULL;
   211   if ((!n1->is_Add() && !n1->is_Sub()) || n1->outcnt() == 0) return NULL;
   212   if (is_invariant(n1)) return NULL;
   212   if (is_invariant(n1)) return NULL;
   213   int inv1_idx = is_invariant_addition(n1, phase);
   213   int inv1_idx = is_invariant_addition(n1, phase);
   214   if (!inv1_idx) return NULL;
   214   if (!inv1_idx) return NULL;
   215   // Don't mess with add of constant (igvn moves them to expression tree root.)
   215   // Don't mess with add of constant (igvn moves them to expression tree root.)
   216   if (n1->is_Add() && n1->in(2)->is_Con()) return NULL;
   216   if (n1->is_Add() && n1->in(2)->is_Con()) return NULL;
   727   }
   727   }
   728 
   728 
   729   // After unroll limit will be adjusted: new_limit = limit-stride.
   729   // After unroll limit will be adjusted: new_limit = limit-stride.
   730   // Bailout if adjustment overflow.
   730   // Bailout if adjustment overflow.
   731   const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int();
   731   const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int();
   732   if (stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi) ||
   732   if ((stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi)) ||
   733       stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo))
   733       (stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo)))
   734     return false;  // overflow
   734     return false;  // overflow
   735 
   735 
   736   // Adjust body_size to determine if we unroll or not
   736   // Adjust body_size to determine if we unroll or not
   737   uint body_size = _body.size();
   737   uint body_size = _body.size();
   738   // Key test to unroll loop in CRC32 java code
   738   // Key test to unroll loop in CRC32 java code
  1411       tty->print("Unroll %d     ", loop_head->unrolled_count()*2);
  1411       tty->print("Unroll %d     ", loop_head->unrolled_count()*2);
  1412     }
  1412     }
  1413     loop->dump_head();
  1413     loop->dump_head();
  1414   }
  1414   }
  1415 
  1415 
  1416   if (C->do_vector_loop() && (PrintOpto && VerifyLoopOptimizations || TraceLoopOpts)) {
  1416   if (C->do_vector_loop() && (PrintOpto && (VerifyLoopOptimizations || TraceLoopOpts))) {
  1417     Arena* arena = Thread::current()->resource_area();
  1417     Arena* arena = Thread::current()->resource_area();
  1418     Node_Stack stack(arena, C->live_nodes() >> 2);
  1418     Node_Stack stack(arena, C->live_nodes() >> 2);
  1419     Node_List rpo_list;
  1419     Node_List rpo_list;
  1420     VectorSet visited(arena);
  1420     VectorSet visited(arena);
  1421     visited.set(loop_head->_idx);
  1421     visited.set(loop_head->_idx);
  1514         assert(has_ctrl(opaq), "should have it");
  1514         assert(has_ctrl(opaq), "should have it");
  1515         Node* opaq_ctrl = get_ctrl(opaq);
  1515         Node* opaq_ctrl = get_ctrl(opaq);
  1516         limit = new Opaque2Node( C, limit );
  1516         limit = new Opaque2Node( C, limit );
  1517         register_new_node( limit, opaq_ctrl );
  1517         register_new_node( limit, opaq_ctrl );
  1518       }
  1518       }
  1519       if (stride_con > 0 && (java_subtract(limit_type->_lo, stride_con) < limit_type->_lo) ||
  1519       if ((stride_con > 0 && (java_subtract(limit_type->_lo, stride_con) < limit_type->_lo)) ||
  1520           stride_con < 0 && (java_subtract(limit_type->_hi, stride_con) > limit_type->_hi)) {
  1520           (stride_con < 0 && (java_subtract(limit_type->_hi, stride_con) > limit_type->_hi))) {
  1521         // No underflow.
  1521         // No underflow.
  1522         new_limit = new SubINode(limit, stride);
  1522         new_limit = new SubINode(limit, stride);
  1523       } else {
  1523       } else {
  1524         // (limit - stride) may underflow.
  1524         // (limit - stride) may underflow.
  1525         // Clamp the adjustment value with MININT or MAXINT:
  1525         // Clamp the adjustment value with MININT or MAXINT:
  1650   }
  1650   }
  1651 
  1651 
  1652   loop->record_for_igvn();
  1652   loop->record_for_igvn();
  1653 
  1653 
  1654 #ifndef PRODUCT
  1654 #ifndef PRODUCT
  1655   if (C->do_vector_loop() && (PrintOpto && VerifyLoopOptimizations || TraceLoopOpts)) {
  1655   if (C->do_vector_loop() && (PrintOpto && (VerifyLoopOptimizations || TraceLoopOpts))) {
  1656     tty->print("\nnew loop after unroll\n");       loop->dump_head();
  1656     tty->print("\nnew loop after unroll\n");       loop->dump_head();
  1657     for (uint i = 0; i < loop->_body.size(); i++) {
  1657     for (uint i = 0; i < loop->_body.size(); i++) {
  1658       loop->_body.at(i)->dump();
  1658       loop->_body.at(i)->dump();
  1659     }
  1659     }
  1660     if(C->clone_map().is_debug()) {
  1660     if(C->clone_map().is_debug()) {