src/hotspot/share/opto/addnode.cpp
author vromero
Mon, 08 Oct 2018 06:52:41 -0700
changeset 52038 957de5be48bc
parent 47216 71c04702a3d5
child 55604 a30c86af2eb7
permissions -rw-r--r--
8209407: VerifyError is thrown for inner class with lambda Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13895
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    27
#include "opto/addnode.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 14828
diff changeset
    28
#include "opto/castnode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    29
#include "opto/cfgnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    30
#include "opto/connode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    31
#include "opto/machnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    32
#include "opto/mulnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    33
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    34
#include "opto/subnode.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6433
diff changeset
    36
// Portions of code courtesy of Clifford Click
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// Classic Add functionality.  This covers all the usual 'add' behaviors for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// an algebraic ring.  Add-integer, add-float, add-double, and binary-or are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// all inherited from this class.  The various identity values are supplied
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// by virtual functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//------------------------------hash-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Hash function over AddNodes.  Needs to be commutative; i.e., I swap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// (commute) inputs to AddNodes willy-nilly so the hash function must return
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// the same value in the presence of edge swapping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
uint AddNode::hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// If either input is a constant 0, return the other input.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
    55
Node* AddNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  const Type *zero = add_id();  // The additive identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//------------------------------commute----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// Commute operands to move loads and constants to the right.
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
    64
static bool commute(Node *add, bool con_left, bool con_right) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  Node *in1 = add->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  Node *in2 = add->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // Convert "1+x" into "x+1".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Right is a constant; leave it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if( con_right ) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // Left is a constant; move it right.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  if( con_left ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    add->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Convert "Load+x" into "x+Load".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Now check for loads
346
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    79
  if (in2->is_Load()) {
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    80
    if (!in1->is_Load()) {
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    81
      // already x+Load to return
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    82
      return false;
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    83
    }
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    84
    // both are loads, so fall through to sort inputs by idx
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    85
  } else if( in1->is_Load() ) {
e13ccc474a28 6680594: Load + Load isn't canonicalized leading to missed GVN opportunities
never
parents: 205
diff changeset
    86
    // Left is a Load and Right is not; move it right.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    add->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  PhiNode *phi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Check for tight loop increments: Loop-phi of Add of loop-phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    add->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Otherwise, sort inputs (commutativity) to help value numbering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if( in1->_idx > in2->_idx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    add->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
// If we get here, we assume we are associative!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  const Type *t2 = phase->type( in(2) );
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
   113
  bool con_left  = t1->singleton();
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
   114
  bool con_right = t2->singleton();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // Check for commutative operation desired
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if( commute(this,con_left,con_right) ) return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  AddNode *progress = NULL;             // Progress flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Convert "(x+1)+2" into "x+(1+2)".  If the right input is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // constant, and the left input is an add of a constant, flatten the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // expression tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  Node *add1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  Node *add2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  int add1_op = add1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  int this_op = Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  if( con_right && t2 != Type::TOP && // Right input is a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      add1_op == this_op ) { // Left input is an Add?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    // Type of left _in right input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    const Type *t12 = phase->type( add1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      // Check for rare case of closed data cycle which can happen inside
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      // unreachable loops. In these cases the computation is undefined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      Node *add11    = add1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      int   add11_op = add11->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      if( (add1 == add1->in(1))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
         || (add11_op == this_op && add11->in(1) == add1) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        assert(false, "dead loop in AddNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      // The Add of the flattened expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      Node *x1 = add1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      PhaseIterGVN *igvn = phase->is_IterGVN();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if( igvn ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        set_req_X(2,x2,igvn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        set_req_X(1,x1,igvn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        set_req(2,x2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        set_req(1,x1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      progress = this;            // Made progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      add1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      add1_op = add1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Convert "(x+1)+y" into "(x+y)+1".  Push constants down the expression tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  if( add1_op == this_op && !con_right ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    Node *a12 = add1->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    const Type *t12 = phase->type( a12 );
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   165
    if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   166
       !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
1124
4de0b4f7eae3 6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents: 1068
diff changeset
   167
      assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      add2 = add1->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      add2->set_req(2, in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      add2 = phase->transform(add2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      set_req(1, add2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      set_req(2, a12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      progress = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      add2 = a12;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // Convert "x+(y+1)" into "(x+y)+1".  Push constants down the expression tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  int add2_op = add2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if( add2_op == this_op && !con_left ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    Node *a22 = add2->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    const Type *t22 = phase->type( a22 );
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   183
    if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   184
       !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
1124
4de0b4f7eae3 6676462: JVM sometimes would suddenly consume significant amount of memory
kvn
parents: 1068
diff changeset
   185
      assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      Node *addx = add2->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      addx->set_req(1, in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      addx->set_req(2, add2->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      addx = phase->transform(addx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      set_req(1, addx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      set_req(2, a22);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      progress = this;
14828
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   193
      PhaseIterGVN *igvn = phase->is_IterGVN();
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   194
      if (add2->outcnt() == 0 && igvn) {
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   195
        // add disconnected.
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   196
        igvn->_worklist.push(add2);
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   197
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  return progress;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
//------------------------------Value-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// An add node sums it's two _in.  If one input is an RSD, we must mixin
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// the other input's symbols.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   207
const Type* AddNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  const Type *bot = bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  if( (t1 == bot) || (t2 == bot) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    return bot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Check for an addition involving the additive identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  const Type *tadd = add_of_identity( t1, t2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if( tadd ) return tadd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  return add_ring(t1,t2);               // Local flavor of type addition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
//------------------------------add_identity-----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// Check for addition of the identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  const Type *zero = add_id();  // The additive identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if( t1->higher_equal( zero ) ) return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  if( t2->higher_equal( zero ) ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   241
  Node* in1 = in(1);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   242
  Node* in2 = in(2);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   243
  int op1 = in1->Opcode();
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   244
  int op2 = in2->Opcode();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // Fold (con1-x)+con2 into (con1+con2)-x
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   246
  if ( op1 == Op_AddI && op2 == Op_SubI ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   247
    // Swap edges to try optimizations below
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   248
    in1 = in2;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   249
    in2 = in(1);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   250
    op1 = op2;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   251
    op2 = in2->Opcode();
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   252
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if( op1 == Op_SubI ) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   254
    const Type *t_sub1 = phase->type( in1->in(1) );
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   255
    const Type *t_2    = phase->type( in2        );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   257
      return new SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    if( op2 == Op_SubI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      // Check for dead cycle: d = (a-b)+(c-d)
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   261
      assert( in1->in(2) != this && in2->in(2) != this,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
              "dead loop in AddINode::Ideal" );
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   263
      Node *sub  = new SubINode(NULL, NULL);
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   264
      sub->init_req(1, phase->transform(new AddINode(in1->in(1), in2->in(1) ) ));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   265
      sub->init_req(2, phase->transform(new AddINode(in1->in(2), in2->in(2) ) ));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      return sub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   268
    // Convert "(a-b)+(b+c)" into "(a+c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   269
    if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   270
      assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   271
      return new AddINode(in1->in(1), in2->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   272
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   273
    // Convert "(a-b)+(c+b)" into "(a+c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   274
    if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   275
      assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   276
      return new AddINode(in1->in(1), in2->in(1));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   277
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   278
    // Convert "(a-b)+(b-c)" into "(a-c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   279
    if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   280
      assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   281
      return new SubINode(in1->in(1), in2->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   282
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   283
    // Convert "(a-b)+(c-a)" into "(c-b)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   284
    if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   285
      assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   286
      return new SubINode(in2->in(1), in1->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   287
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // Convert "x+(0-y)" into "(x-y)"
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   291
  if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   292
    return new SubINode(in1, in2->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // Convert "(0-y)+x" into "(x-y)"
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   295
  if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   296
    return new SubINode( in2, in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // Helps with array allocation math constant folding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // See 4790063:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // Unrestricted transformation is unsafe for some runtime values of 'x'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  // ( x ==  0, z == 1, y == -1 ) fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // ( x == -5, z == 1, y ==  1 ) fails
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Transform works for small z and small negative y when the addition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // (x + (y << z)) does not cross zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // Implement support for negative y and (x >= -(y << z))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  // Have not observed cases where type information exists to support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // positive y and (x <= -(y << z))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  if( op1 == Op_URShiftI && op2 == Op_ConI &&
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   310
      in1->in(2)->Opcode() == Op_ConI ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   311
    jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   312
    jint y = phase->type( in2 )->is_int()->get_con();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    if( z < 5 && -5 < y && y < 0 ) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   315
      const Type *t_in11 = phase->type(in1->in(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   317
        Node *a = phase->transform( new AddINode( in1->in(1), phase->intcon(y<<z) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   318
        return new URShiftINode( a, in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  return AddNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// Fold (x-y)+y  OR  y+(x-y)  into  x
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   329
Node* AddINode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    return in(2)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  return AddNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
// Supplied function returns the sum of the inputs.  Guaranteed never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// to be passed a TOP or BOTTOM type, these are filtered out by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  const TypeInt *r1 = t1->is_int();
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 24923
diff changeset
   347
  int lo = java_add(r0->_lo, r1->_lo);
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 24923
diff changeset
   348
  int hi = java_add(r0->_hi, r1->_hi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  if( !(r0->is_con() && r1->is_con()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    // Not both constants, compute approximate result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      lo = min_jint; hi = max_jint; // Underflow on the low side
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      lo = min_jint; hi = max_jint; // Overflow on the high side
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if( lo > hi ) {               // Handle overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      lo = min_jint; hi = max_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // both constants, compute precise result using 'lo' and 'hi'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    // Semantics define overflow and underflow for integer addition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    // as expected.  In particular: 0x80000000 + 0x80000000 --> 0x0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   372
  Node* in1 = in(1);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   373
  Node* in2 = in(2);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   374
  int op1 = in1->Opcode();
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   375
  int op2 = in2->Opcode();
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   376
  // Fold (con1-x)+con2 into (con1+con2)-x
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   377
  if ( op1 == Op_AddL && op2 == Op_SubL ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   378
    // Swap edges to try optimizations below
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   379
    in1 = in2;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   380
    in2 = in(1);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   381
    op1 = op2;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   382
    op2 = in2->Opcode();
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   383
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // Fold (con1-x)+con2 into (con1+con2)-x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  if( op1 == Op_SubL ) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   386
    const Type *t_sub1 = phase->type( in1->in(1) );
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   387
    const Type *t_2    = phase->type( in2        );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   389
      return new SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ), in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    if( op2 == Op_SubL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      // Check for dead cycle: d = (a-b)+(c-d)
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   393
      assert( in1->in(2) != this && in2->in(2) != this,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
              "dead loop in AddLNode::Ideal" );
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   395
      Node *sub  = new SubLNode(NULL, NULL);
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   396
      sub->init_req(1, phase->transform(new AddLNode(in1->in(1), in2->in(1) ) ));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   397
      sub->init_req(2, phase->transform(new AddLNode(in1->in(2), in2->in(2) ) ));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      return sub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    }
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   400
    // Convert "(a-b)+(b+c)" into "(a+c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   401
    if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   402
      assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   403
      return new AddLNode(in1->in(1), in2->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   404
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   405
    // Convert "(a-b)+(c+b)" into "(a+c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   406
    if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   407
      assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   408
      return new AddLNode(in1->in(1), in2->in(1));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   409
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   410
    // Convert "(a-b)+(b-c)" into "(a-c)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   411
    if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   412
      assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   413
      return new SubLNode(in1->in(1), in2->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   414
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   415
    // Convert "(a-b)+(c-a)" into "(c-b)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   416
    if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   417
      assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   418
      return new SubLNode(in2->in(1), in1->in(2));
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   419
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // Convert "x+(0-y)" into "(x-y)"
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   423
  if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   424
    return new SubLNode( in1, in2->in(2) );
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   425
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   426
  // Convert "(0-y)+x" into "(x-y)"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   427
  if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   428
    return new SubLNode( in2, in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  // into "(X<<1)+Y" and let shift-folding happen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  if( op2 == Op_AddL &&
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1124
diff changeset
   433
      in2->in(1) == in1 &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      op1 != Op_ConL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      0 ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   436
    Node *shift = phase->transform(new LShiftLNode(in1,phase->intcon(1)));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   437
    return new AddLNode(shift,in2->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  return AddNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
// Fold (x-y)+y  OR  y+(x-y)  into  x
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   446
Node* AddLNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    return in(2)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  return AddNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
// Supplied function returns the sum of the inputs.  Guaranteed never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
// to be passed a TOP or BOTTOM type, these are filtered out by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
// pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  const TypeLong *r0 = t0->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  const TypeLong *r1 = t1->is_long();
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 24923
diff changeset
   464
  jlong lo = java_add(r0->_lo, r1->_lo);
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 24923
diff changeset
   465
  jlong hi = java_add(r0->_hi, r1->_hi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  if( !(r0->is_con() && r1->is_con()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    // Not both constants, compute approximate result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      lo =min_jlong; hi = max_jlong; // Underflow on the low side
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      lo = min_jlong; hi = max_jlong; // Overflow on the high side
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    if( lo > hi ) {               // Handle overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      lo = min_jlong; hi = max_jlong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    // both constants, compute precise result using 'lo' and 'hi'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    // Semantics define overflow and underflow for integer addition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    // as expected.  In particular: 0x80000000 + 0x80000000 --> 0x0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
//------------------------------add_of_identity--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
// Check for addition of the identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  // x ADD 0  should return x unless 'x' is a -zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // const Type *zero = add_id();     // The additive identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  // jfloat f1 = t1->getf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  // jfloat f2 = t2->getf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // if( t1->higher_equal( zero ) ) return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  // if( t2->higher_equal( zero ) ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
// Supplied function returns the sum of the inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  // We must be adding 2 float constants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  return TypeF::make( t0->getf() + t1->getf() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // Floating point additions are not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  return commute(this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
                 phase->type( in(1) )->singleton(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
                 phase->type( in(2) )->singleton() ) ? this : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
//------------------------------add_of_identity--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
// Check for addition of the identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // x ADD 0  should return x unless 'x' is a -zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  // const Type *zero = add_id();     // The additive identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  // jfloat f1 = t1->getf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  // jfloat f2 = t2->getf();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  // if( t1->higher_equal( zero ) ) return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  // if( t2->higher_equal( zero ) ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
// Supplied function returns the sum of the inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // We must be adding 2 double constants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  return TypeD::make( t0->getd() + t1->getd() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // Floating point additions are not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  return commute(this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
                 phase->type( in(1) )->singleton(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
                 phase->type( in(2) )->singleton() ) ? this : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
// If one input is a constant 0, return the other input.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   564
Node* AddPNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // Bail out if dead inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  if( phase->type( in(Address) ) == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // If the left input is an add of a constant, flatten the expression tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  const Node *n = in(Address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  if (n->is_AddP() && n->in(Base) == in(Base)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    const AddPNode *addp = n->as_AddP(); // Left input is an AddP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    assert( !addp->in(Address)->is_AddP() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
             addp->in(Address)->as_AddP() != addp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
            "dead loop in AddPNode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    // Type of left input's right input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    const Type *t = phase->type( addp->in(Offset) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    if( t == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    const TypeX *t12 = t->is_intptr_t();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    if( t12->is_con() ) {       // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      // If the right input is a constant, combine constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      const Type *temp_t2 = phase->type( in(Offset) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      if( temp_t2 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      const TypeX *t2 = temp_t2->is_intptr_t();
205
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   589
      Node* address;
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   590
      Node* offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
      if( t2->is_con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
        // The Add of the flattened expression
205
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   593
        address = addp->in(Address);
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   594
        offset  = phase->MakeConX(t2->get_con() + t12->get_con());
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   595
      } else {
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   596
        // Else move the constant to the right.  ((A+con)+B) into ((A+B)+con)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   597
        address = phase->transform(new AddPNode(in(Base),addp->in(Address),in(Offset)));
205
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   598
        offset  = addp->in(Offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
      }
205
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   600
      PhaseIterGVN *igvn = phase->is_IterGVN();
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   601
      if( igvn ) {
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   602
        set_req_X(Address,address,igvn);
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   603
        set_req_X(Offset,offset,igvn);
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   604
      } else {
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   605
        set_req(Address,address);
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   606
        set_req(Offset,offset);
4069fc169258 6667573: Use set_req_X() in AddPNode::Ideal() for Iterative GVN
kvn
parents: 190
diff changeset
   607
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // Raw pointers?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  if( in(Base)->bottom_type() == Type::TOP ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
      Node* offset = in(Offset);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   617
      return new CastX2PNode(offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  // If the right is an add of a constant, push the offset down.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // The idea is to merge array_base+scaled_index groups together,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  // and only have different constant offsets from the same base.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  const Node *add = in(Offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  if( add->Opcode() == Op_AddX && add->in(1) != add ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    const Type *t22 = phase->type( add->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    if( t22->singleton() && (t22 != Type::TOP) ) {  // Right input is an add of a constant?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   629
      set_req(Address, phase->transform(new AddPNode(in(Base),in(Address),add->in(1))));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
      set_req(Offset, add->in(2));
14828
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   631
      PhaseIterGVN *igvn = phase->is_IterGVN();
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   632
      if (add->outcnt() == 0 && igvn) {
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   633
        // add disconnected.
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   634
        igvn->_worklist.push((Node*)add);
bb9dffedf46c 8005031: Some cleanup in c2 to prepare for incremental inlining support
roland
parents: 13963
diff changeset
   635
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
      return this;              // Made progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  return NULL;                  // No progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
//------------------------------bottom_type------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
// Bottom-type is the pointer-type with unknown offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
const Type *AddPNode::bottom_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  if (in(Address) == NULL)  return TypePtr::BOTTOM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  if( !tp ) return Type::TOP;   // TOP input means TOP output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  assert( in(Offset)->Opcode() != Op_ConP, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  const Type *t = in(Offset)->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  if( t == Type::TOP )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    return tp->add_offset(Type::OffsetTop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  const TypeX *tx = t->is_intptr_t();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  intptr_t txoffset = Type::OffsetBot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  if (tx->is_con()) {   // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    txoffset = tx->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  return tp->add_offset(txoffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   662
const Type* AddPNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  const Type *t1 = phase->type( in(Address) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  const Type *t2 = phase->type( in(Offset) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  // Left input is a pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  const TypePtr *p1 = t1->isa_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  // Right input is an int
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  const TypeX *p2 = t2->is_intptr_t();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  // Add 'em
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  intptr_t p2offset = Type::OffsetBot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  if (p2->is_con()) {   // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    p2offset = p2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  return p1->add_offset(p2offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
//------------------------Ideal_base_and_offset--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
// Split an oop pointer into a base and offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
// (The offset might be Type::OffsetBot in the case of an array.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
// Return the base, or NULL if failure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
                                      // second return value:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                                      intptr_t& offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  if (ptr->is_AddP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    Node* base = ptr->in(AddPNode::Base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    Node* addr = ptr->in(AddPNode::Address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    Node* offs = ptr->in(AddPNode::Offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    if (base == addr || base->is_top()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      offset = phase->find_intptr_t_con(offs, Type::OffsetBot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      if (offset != Type::OffsetBot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        return addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  offset = Type::OffsetBot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
190
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   703
//------------------------------unpack_offsets----------------------------------
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   704
// Collect the AddP offset values into the elements array, giving up
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   705
// if there are more than length.
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   706
int AddPNode::unpack_offsets(Node* elements[], int length) {
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   707
  int count = 0;
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   708
  Node* addr = this;
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   709
  Node* base = addr->in(AddPNode::Base);
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   710
  while (addr->is_AddP()) {
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   711
    if (addr->in(AddPNode::Base) != base) {
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   712
      // give up
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   713
      return -1;
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   714
    }
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   715
    elements[count++] = addr->in(AddPNode::Offset);
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   716
    if (count == length) {
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   717
      // give up
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   718
      return -1;
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   719
    }
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   720
    addr = addr->in(AddPNode::Address);
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   721
  }
6433
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   722
  if (addr != base) {
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   723
    return -1;
b0e4fafdc38b 4809552: Optimize Arrays.fill(...)
never
parents: 5547
diff changeset
   724
  }
190
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   725
  return count;
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   726
}
e9a0a9dcd4f6 6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents: 1
diff changeset
   727
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
//------------------------------match_edge-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
// Do we Match on this edge index or not?  Do not match base pointer edge
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
uint AddPNode::match_edge(uint idx) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  return idx > Base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   736
Node* OrINode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  // x | x => x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  if (phase->eqv(in(1), in(2))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  return AddNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
// Supplied function returns the sum of the inputs IN THE CURRENT RING.  For
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
// the logical operations the ring's ADD is really a logical OR function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  // If both args are bool, can figure out better types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  if ( r0 == TypeInt::BOOL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    if ( r1 == TypeInt::ONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
      return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    } else if ( r1 == TypeInt::BOOL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  } else if ( r0 == TypeInt::ONE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    if ( r1 == TypeInt::BOOL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
      return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  // If either input is not a constant, just return all integers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  if( !r0->is_con() || !r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    return TypeInt::INT;        // Any integer, but still no symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  // Otherwise just OR them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  return TypeInt::make( r0->get_con() | r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   777
Node* OrLNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  // x | x => x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  if (phase->eqv(in(1), in(2))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  return AddNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  const TypeLong *r0 = t0->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  const TypeLong *r1 = t1->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  // If either input is not a constant, just return all integers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  if( !r0->is_con() || !r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    return TypeLong::LONG;      // Any integer, but still no symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  // Otherwise just OR them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  return TypeLong::make( r0->get_con() | r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
// Supplied function returns the sum of the inputs IN THE CURRENT RING.  For
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
// the logical operations the ring's ADD is really a logical OR function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  // Complementing a boolean?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
                               || r1 == TypeInt::BOOL))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  if( !r0->is_con() || !r1->is_con() ) // Not constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    return TypeInt::INT;        // Any integer, but still no symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  // Otherwise just XOR them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  return TypeInt::make( r0->get_con() ^ r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  const TypeLong *r0 = t0->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  const TypeLong *r1 = t1->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  // If either input is not a constant, just return all integers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  if( !r0->is_con() || !r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    return TypeLong::LONG;      // Any integer, but still no symbols.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  // Otherwise just OR them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  return TypeLong::make( r0->get_con() ^ r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
// Supplied function returns the sum of the inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  // Otherwise just MAX them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
// MINs show up in range-check loop limit calculations.  Look for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
// "MIN2(x+c0,MIN2(y,x+c1))".  Pick the smaller constant: "MIN2(x+c0,y)"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  Node *progress = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  // Force a right-spline graph
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  Node *l = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  Node *r = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // Transform  MinI1( MinI2(a,b), c)  into  MinI1( a, MinI2(b,c) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  // to force a right-spline graph for the rest of MinINode::Ideal().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  if( l->Opcode() == Op_MinI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    assert( l != l->in(1), "dead loop in MinINode::Ideal" );
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   859
    r = phase->transform(new MinINode(l->in(2),r));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    l = l->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    set_req(1, l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    set_req(2, r);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // Get left input & constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  Node *x = l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  int x_off = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
      x->in(2)->is_Con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    const Type *t = x->in(2)->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    if( t == Type::TOP ) return NULL;  // No progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    x_off = t->is_int()->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    x = x->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  // Scan a right-spline-tree for MINs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  Node *y = r;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  int y_off = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  // Check final part of MIN tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      y->in(2)->is_Con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    const Type *t = y->in(2)->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    if( t == Type::TOP ) return NULL;  // No progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
    y_off = t->is_int()->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    y = y->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  if( r->Opcode() == Op_MinI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
    assert( r != r->in(2), "dead loop in MinINode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    y = r->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    // Check final part of MIN tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
    if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
        y->in(2)->is_Con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
      const Type *t = y->in(2)->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
      if( t == Type::TOP ) return NULL;  // No progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
      y_off = t->is_int()->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      y = y->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    if( x->_idx > y->_idx )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   907
      return new MinINode(r->in(1),phase->transform(new MinINode(l,r->in(2))));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    // See if covers: MIN2(x+c0,MIN2(y+c1,z))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    if( !phase->eqv(x,y) ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    // MIN2(x+c0 or x+c1 which less, z).
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   913
    return new MinINode(phase->transform(new AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    // See if covers: MIN2(x+c0,y+c1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
    if( !phase->eqv(x,y) ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
    // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less.
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   918
    return new AddINode(x,phase->intcon(MIN2(x_off,y_off)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
//------------------------------add_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
// Supplied function returns the sum of the inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  // Otherwise just MIN them bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
}