< prev index next >

src/hotspot/share/opto/loopopts.cpp

Print this page

   1 /*
   2  * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

 504     return res;
 505   }
 506 
 507   int n_op = n->Opcode();
 508   // Replace (I+V) with (V+I)
 509   if (n_op == Op_AddI ||
 510       n_op == Op_AddL ||
 511       n_op == Op_AddF ||
 512       n_op == Op_AddD ||
 513       n_op == Op_MulI ||
 514       n_op == Op_MulL ||
 515       n_op == Op_MulF ||
 516       n_op == Op_MulD) {
 517     if (n2_loop == n_loop) {
 518       assert(n1_loop != n_loop, "");
 519       n->swap_edges(1, 2);
 520     }
 521   }
 522 
 523   // Replace ((I1 +p V) +p I2) with ((I1 +p I2) +p V),
 524   // but not if I2 is a constant.
 525   if (n_op == Op_AddP) {
 526     if (n2_loop == n_loop && n3_loop != n_loop) {
 527       if (n->in(2)->Opcode() == Op_AddP && !n->in(3)->is_Con()) {
 528         Node* n22_ctrl = get_ctrl(n->in(2)->in(2));
 529         Node* n23_ctrl = get_ctrl(n->in(2)->in(3));
 530         IdealLoopTree* n22loop = get_loop(n22_ctrl);
 531         IdealLoopTree* n23_loop = get_loop(n23_ctrl);
 532         if (n22loop != n_loop && n22loop->is_member(n_loop) &&
 533             n23_loop == n_loop) {
 534           Node* add1 = new AddPNode(n->in(1), n->in(2)->in(2), n->in(3));
 535           // Stuff new AddP in the loop preheader
 536           register_new_node(add1, n_loop->_head->as_Loop()->skip_strip_mined(1)->in(LoopNode::EntryControl));
 537           Node* add2 = new AddPNode(n->in(1), add1, n->in(2)->in(3));
 538           register_new_node(add2, n_ctrl);
 539           _igvn.replace_node(n, add2);
 540           return add2;
 541         }
 542       }
 543     }
 544 
 545     // Replace (I1 +p (I2 + V)) with ((I1 +p I2) +p V)

   1 /*
   2  * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *

 504     return res;
 505   }
 506 
 507   int n_op = n->Opcode();
 508   // Replace (I+V) with (V+I)
 509   if (n_op == Op_AddI ||
 510       n_op == Op_AddL ||
 511       n_op == Op_AddF ||
 512       n_op == Op_AddD ||
 513       n_op == Op_MulI ||
 514       n_op == Op_MulL ||
 515       n_op == Op_MulF ||
 516       n_op == Op_MulD) {
 517     if (n2_loop == n_loop) {
 518       assert(n1_loop != n_loop, "");
 519       n->swap_edges(1, 2);
 520     }
 521   }
 522 
 523   // Replace ((I1 +p V) +p I2) with ((I1 +p I2) +p V),
 524   // but not if I2 is a constant. Skip for irreducible loops.
 525   if (n_op == Op_AddP && n_loop->_head->is_Loop()) {
 526     if (n2_loop == n_loop && n3_loop != n_loop) {
 527       if (n->in(2)->Opcode() == Op_AddP && !n->in(3)->is_Con()) {
 528         Node* n22_ctrl = get_ctrl(n->in(2)->in(2));
 529         Node* n23_ctrl = get_ctrl(n->in(2)->in(3));
 530         IdealLoopTree* n22loop = get_loop(n22_ctrl);
 531         IdealLoopTree* n23_loop = get_loop(n23_ctrl);
 532         if (n22loop != n_loop && n22loop->is_member(n_loop) &&
 533             n23_loop == n_loop) {
 534           Node* add1 = new AddPNode(n->in(1), n->in(2)->in(2), n->in(3));
 535           // Stuff new AddP in the loop preheader
 536           register_new_node(add1, n_loop->_head->as_Loop()->skip_strip_mined(1)->in(LoopNode::EntryControl));
 537           Node* add2 = new AddPNode(n->in(1), add1, n->in(2)->in(3));
 538           register_new_node(add2, n_ctrl);
 539           _igvn.replace_node(n, add2);
 540           return add2;
 541         }
 542       }
 543     }
 544 
 545     // Replace (I1 +p (I2 + V)) with ((I1 +p I2) +p V)
< prev index next >