hotspot/src/share/vm/opto/subnode.cpp
author kvn
Thu, 13 Mar 2008 16:06:34 -0700
changeset 236 9a04268c8eea
parent 206 d61cf247afd5
child 360 21d113ecbf6a
permissions -rw-r--r--
6671807: (Escape Analysis) Add new ideal node to represent the state of a scalarized object at a safepoint Summary: Values of non-static fields of a scalarized object should be saved in debug info to reallocate the object during deoptimization. Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Portions of code courtesy of Clifford Click
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// Optimization - Graph Style
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#include "incls/_subnode.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#include "math.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// If right input is a constant 0, return the left input.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
Node *SubNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  assert(in(1) != this, "Must already have called Value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(in(2) != this, "Must already have called Value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Remove double negation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  const Type *zero = add_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  if( phase->type( in(1) )->higher_equal( zero ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      in(2)->Opcode() == Opcode() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
      phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    return in(2)->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Convert "(X+Y) - Y" into X
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if( in(1)->Opcode() == Op_AddI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    if( phase->eqv(in(1)->in(2),in(2)) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    // Also catch: "(X + Opaque2(Y)) - Y".  In this case, 'Y' is a loop-varying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // trip counter and X is likely to be loop-invariant (that's how O2 Nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    // are originally used, although the optimizer sometimes jiggers things).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // This folding through an O2 removes a loop-exit use of a loop-varying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // value and generally lowers register pressure in and around the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
        phase->eqv(in(1)->in(2)->in(1),in(2)) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
// A subtract node differences it's two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
const Type *SubNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Not correct for SubFnode and AddFNode (must check for infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Equal?  Subtract is zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  if (phase->eqv_uncast(in1, in2))  return add_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  return sub(t1,t2);            // Local flavor of type subtraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
//------------------------------Helper function--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
static bool ok_to_convert(Node* inc, Node* iv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // Do not collapse (x+c0)-y if "+" is a loop increment, because the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // "-" is loop invariant and collapsing extends the live-range of "x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    // to overlap with the "+", forcing another register to be used in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // This test will be clearer with '&&' (apply DeMorgan's rule)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // but I like the early cutouts that happen here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    const PhiNode *phi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if( ( !inc->in(1)->is_Phi() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
          !(phi=inc->in(1)->as_Phi()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
          phi->is_copy() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
          !phi->region()->is_CountedLoop() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
          inc != phi->region()->as_CountedLoop()->incr() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
       &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        // Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        // because "x" maybe invariant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        ( !iv->is_loop_iv() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  Node *in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  Node *in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  uint op1 = in1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  uint op2 = in2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      ( op1 == Op_AddI || op1 == Op_SubI ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        phase->eqv( in1->in(1), in1  ) || phase->eqv( in1->in(2), in1 ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(false, "dead loop in SubINode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  const Type *t2 = phase->type( in2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  if( t2 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  if( t2->base() == Type::Int ){        // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    const TypeInt *i = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    if( i->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      return new (phase->C, 3) AddINode(in1, phase->intcon(-i->get_con()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Convert "(x+c0) - y" into (x-y) + c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Do not collapse (x+c0)-y if "+" is a loop increment or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // if "y" is a loop induction variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    const Type *tadd = phase->type( in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if( tadd->singleton() && tadd != Type::TOP ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      Node *sub2 = phase->transform( new (phase->C, 3) SubINode( in1->in(1), in2 ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      return new (phase->C, 3) AddINode( sub2, in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Convert "x - (y+c0)" into "(x-y) - c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // Need the same check as in above optimization but reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  if (op2 == Op_AddI && ok_to_convert(in2, in1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    Node* in21 = in2->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    Node* in22 = in2->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    const TypeInt* tcon = phase->type(in22)->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (tcon != NULL && tcon->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      Node* sub2 = phase->transform( new (phase->C, 3) SubINode(in1, in21) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      Node* neg_c0 = phase->intcon(- tcon->get_con());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      return new (phase->C, 3) AddINode(sub2, neg_c0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  const Type *t1 = phase->type( in1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if( t1 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  if( ( op2 == Op_AddI || op2 == Op_SubI ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
        phase->eqv( in2->in(1), in2  ) || phase->eqv( in2->in(2), in2  ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    assert(false, "dead loop in SubINode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  if( op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      phase->eqv( in1, in2->in(1) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return new (phase->C, 3) SubINode( phase->intcon(0),in2->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Convert "(x-y) - x" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if( op1 == Op_SubI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      phase->eqv( in1->in(1), in2 ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    return new (phase->C, 3) SubINode( phase->intcon(0),in1->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Convert "x - (y+x)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if( op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      phase->eqv( in1, in2->in(2) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    return new (phase->C, 3) SubINode( phase->intcon(0),in2->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Convert "0 - (x-y)" into "y-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  if( t1 == TypeInt::ZERO && op2 == Op_SubI )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    return new (phase->C, 3) SubINode( in2->in(2), in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // Convert "0 - (x+con)" into "-con-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  jint con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      (con = in2->in(2)->find_int_con(0)) != 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    return new (phase->C, 3) SubINode( phase->intcon(-con), in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Convert "(X+A) - (X+B)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return new (phase->C, 3) SubINode( in1->in(2), in2->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // Convert "(A+X) - (B+X)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    return new (phase->C, 3) SubINode( in1->in(1), in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // nicer to optimize than subtract.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if( op2 == Op_SubI && in2->outcnt() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    Node *add1 = phase->transform( new (phase->C, 3) AddINode( in1, in2->in(2) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    return new (phase->C, 3) SubINode( add1, in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// A subtract node differences it's two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  const TypeInt *r0 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  const TypeInt *r1 = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  int32 lo = r0->_lo - r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  int32 hi = r0->_hi - r1->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // We next check for 32-bit overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // If that happens, we just assume all integers are possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
       ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
       ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  else                          // Overflow; assume all integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  Node *in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  Node *in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  uint op1 = in1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  uint op2 = in2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      ( op1 == Op_AddL || op1 == Op_SubL ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        phase->eqv( in1->in(1), in1  ) || phase->eqv( in1->in(2), in1  ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    assert(false, "dead loop in SubLNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  if( phase->type( in2 ) == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  const TypeLong *i = phase->type( in2 )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  if( i &&                      // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      i->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    return new (phase->C, 3) AddLNode(in1, phase->longcon(-i->get_con()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // Convert "(x+c0) - y" into (x-y) + c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // Do not collapse (x+c0)-y if "+" is a loop increment or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // if "y" is a loop induction variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    Node *in11 = in1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    const Type *tadd = phase->type( in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    if( tadd->singleton() && tadd != Type::TOP ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      Node *sub2 = phase->transform( new (phase->C, 3) SubLNode( in11, in2 ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      return new (phase->C, 3) AddLNode( sub2, in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // Convert "x - (y+c0)" into "(x-y) - c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // Need the same check as in above optimization but reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  if (op2 == Op_AddL && ok_to_convert(in2, in1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    Node* in21 = in2->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    Node* in22 = in2->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    const TypeLong* tcon = phase->type(in22)->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    if (tcon != NULL && tcon->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      Node* sub2 = phase->transform( new (phase->C, 3) SubLNode(in1, in21) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      Node* neg_c0 = phase->longcon(- tcon->get_con());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      return new (phase->C, 3) AddLNode(sub2, neg_c0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  const Type *t1 = phase->type( in1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if( t1 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if( ( op2 == Op_AddL || op2 == Op_SubL ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
        phase->eqv( in2->in(1), in2  ) || phase->eqv( in2->in(2), in2  ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    assert(false, "dead loop in SubLNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  if( op2 == Op_AddL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      phase->eqv( in1, in2->in(1) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    return new (phase->C, 3) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // Convert "x - (y+x)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if( op2 == Op_AddL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      phase->eqv( in1, in2->in(2) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return new (phase->C, 3) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Convert "0 - (x-y)" into "y-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    return new (phase->C, 3) SubLNode( in2->in(2), in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // Convert "(X+A) - (X+B)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    return new (phase->C, 3) SubLNode( in1->in(2), in2->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // Convert "(A+X) - (B+X)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    return new (phase->C, 3) SubLNode( in1->in(1), in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // Convert "A-(B-C)" into (A+C)-B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  if( op2 == Op_SubL && in2->outcnt() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    Node *add1 = phase->transform( new (phase->C, 3) AddLNode( in1, in2->in(2) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    return new (phase->C, 3) SubLNode( add1, in2->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// A subtract node differences it's two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  const TypeLong *r0 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  const TypeLong *r1 = t2->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  jlong lo = r0->_lo - r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  jlong hi = r0->_hi - r1->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // We next check for 32-bit overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  // If that happens, we just assume all integers are possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
       ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
       ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  else                          // Overflow; assume all integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
// A subtract node differences its two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
const Type *SubFPNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // if both operands are infinity of same sign, the result is NaN; do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  // not replace with zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  if( (t1->is_finite() && t2->is_finite()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    if( phase->eqv(in1, in2) ) return add_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  const Type *bot = bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  if( (t1 == bot) || (t2 == bot) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    return bot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  return sub(t1,t2);            // Local flavor of type subtraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  if( t2->base() == Type::FloatCon ) {  // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // Not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    if( in(2)->is_Add() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        phase->eqv(in(1),in(2)->in(1) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      return new (phase->C, 3) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  //if( phase->type(in(1)) == TypeF::ZERO )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  //return new (phase->C, 2) NegFNode(in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
// A subtract node differences its two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // no folding if one of operands is infinity or NaN, do not do constant folding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    return TypeF::make( t1->getf() - t2->getf() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  else if( g_isnan(t1->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  else if( g_isnan(t2->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    return Type::FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  if( t2->base() == Type::DoubleCon ) { // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // Not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    if( in(2)->is_Add() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
        phase->eqv(in(1),in(2)->in(1) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      return new (phase->C, 3) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  //if( phase->type(in(1)) == TypeD::ZERO )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  //return new (phase->C, 2) NegDNode(in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
// A subtract node differences its two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  // no folding if one of operands is infinity or NaN, do not do constant folding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    return TypeD::make( t1->getd() - t2->getd() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  else if( g_isnan(t1->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  else if( g_isnan(t2->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
// Unlike SubNodes, compare must still flatten return value to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// range -1, 0, 1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
// And optimizations like those for (X + Y) - X fail if overflow happens.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
Node *CmpNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
// Simplify a CmpI (compare 2 integers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  const TypeInt *r0 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  const TypeInt *r1 = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  if( r0->_hi < r1->_lo )       // Range is always low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  else if( r0->_lo > r1->_hi )  // Range is always high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  else if( r0->is_con() && r1->is_con() ) { // comparing constants?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    assert(r0->get_con() == r1->get_con(), "must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    return TypeInt::CC_EQ;      // Equal results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  } else if( r0->_hi == r1->_lo ) // Range is never high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  else if( r0->_lo == r1->_hi ) // Range is never low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  return TypeInt::CC;           // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
// Simplify a CmpU (compare 2 integers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  assert(!t1->isa_ptr(), "obsolete usage of CmpU");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  // comparing two unsigned ints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  const TypeInt *r0 = t1->is_int();   // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  const TypeInt *r1 = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  // Current installed version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  // Compare ranges for non-overlap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  juint lo0 = r0->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  juint hi0 = r0->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  juint lo1 = r1->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  juint hi1 = r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  // If either one has both negative and positive values,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  // it therefore contains both 0 and -1, and since [0..-1] is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  // full unsigned range, the type must act as an unsigned bottom.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  bool bot0 = ((jint)(lo0 ^ hi0) < 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  bool bot1 = ((jint)(lo1 ^ hi1) < 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  if (bot0 || bot1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    // All unsigned values are LE -1 and GE 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    if (lo0 == 0 && hi0 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      return TypeInt::CC_LE;            //   0 <= bot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    } else if (lo1 == 0 && hi1 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
      return TypeInt::CC_GE;            // bot >= 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    // We can use ranges of the form [lo..hi] if signs are the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    // results are reversed, '-' > '+' for unsigned compare
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    if (hi0 < lo1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      return TypeInt::CC_LT;            // smaller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    } else if (lo0 > hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      return TypeInt::CC_GT;            // greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    } else if (hi0 == lo1 && lo0 == hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      return TypeInt::CC_EQ;            // Equal results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
    } else if (lo0 >= hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    } else if (hi0 <= lo1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
      // Check for special case in Hashtable::get.  (See below.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      if ((jint)lo0 >= 0 && (jint)lo1 >= 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
          in(1)->Opcode() == Op_ModI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
          in(1)->in(2) == in(2) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  // Check for special case in Hashtable::get - the hash index is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  // mod'ed to the table size so the following range check is useless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // to be positive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // (This is a gross hack, since the sub method never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // looks at the structure of the node in any other case.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  if ((jint)lo0 >= 0 && (jint)lo1 >= 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      in(1)->Opcode() == Op_ModI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
      in(1)->in(2)->uncast() == in(2)->uncast())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  return TypeInt::CC;                   // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    switch (in(1)->Opcode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
      return new (phase->C, 3) CmpLNode(in(1)->in(1),in(1)->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      return new (phase->C, 3) CmpFNode(in(1)->in(1),in(1)->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      return new (phase->C, 3) CmpDNode(in(1)->in(1),in(1)->in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    //case Op_SubI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      // If (x - y) cannot overflow, then ((x - y) <?> 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      // can be turned into (x <?> y).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      // This is handled (with more general cases) by Ideal_sub_algebra.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  return NULL;                  // No change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
// Simplify a CmpL (compare 2 longs ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  const TypeLong *r0 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  const TypeLong *r1 = t2->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  if( r0->_hi < r1->_lo )       // Range is always low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  else if( r0->_lo > r1->_hi )  // Range is always high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  else if( r0->is_con() && r1->is_con() ) { // comparing constants?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    assert(r0->get_con() == r1->get_con(), "must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    return TypeInt::CC_EQ;      // Equal results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  } else if( r0->_hi == r1->_lo ) // Range is never high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  else if( r0->_lo == r1->_hi ) // Range is never low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  return TypeInt::CC;           // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
// Simplify an CmpP (compare 2 pointers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  const TypePtr *r0 = t1->is_ptr(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  const TypePtr *r1 = t2->is_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  // Undefined inputs makes for an undefined result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  if( TypePtr::above_centerline(r0->_ptr) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      TypePtr::above_centerline(r1->_ptr) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  if (r0 == r1 && r0->singleton()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    // Equal pointer constants (klasses, nulls, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  // See if it is 2 unrelated classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  const TypeOopPtr* p0 = r0->isa_oopptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  const TypeOopPtr* p1 = r1->isa_oopptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  if (p0 && p1) {
206
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   617
    Node* in1 = in(1)->uncast();
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   618
    Node* in2 = in(2)->uncast();
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   619
    AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   620
    AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   621
    if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   622
      return TypeInt::CC_GT;  // different pointers
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   623
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    ciKlass* klass0 = p0->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    bool    xklass0 = p0->klass_is_exact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    ciKlass* klass1 = p1->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    bool    xklass1 = p1->klass_is_exact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    if (klass0 && klass1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
        kps != 1 &&             // both or neither are klass pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
        !klass0->is_interface() && // do not trust interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
        !klass1->is_interface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      // See if neither subclasses the other, or if the class on top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
      // is precise.  In either of these cases, the compare must fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
      if (klass0->equals(klass1)   ||   // if types are unequal but klasses are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
          !klass0->is_java_klass() ||   // types not part of Java language?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
          !klass1->is_java_klass()) {   // types not part of Java language?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
        // Do nothing; we know nothing for imprecise types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
      } else if (klass0->is_subtype_of(klass1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
        // If klass1's type is PRECISE, then we can fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
        if (xklass1)  return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      } else if (klass1->is_subtype_of(klass0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
        // If klass0's type is PRECISE, then we can fail.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
        if (xklass0)  return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      } else {                  // Neither subtypes the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
        return TypeInt::CC_GT;  // ...so always fail
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // Known constants can be compared exactly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // Null can be distinguished from any NotNull pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  // Unknown inputs makes an unknown result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  if( r0->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    intptr_t bits0 = r0->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    if( r1->singleton() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  } else if( r1->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    intptr_t bits1 = r1->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
// Check for the case of comparing an unknown klass loaded from the primary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
// super-type array vs a known klass with no subtypes.  This amounts to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
// checking to see an unknown klass subtypes a known klass with no subtypes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
// this only happens on an exact match.  We can shorten this test by 1 load.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  // Constant pointer on right?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  if (t2 == NULL || !t2->klass_is_exact())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  // Get the constant klass we are comparing to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  ciKlass* superklass = t2->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  // Now check for LoadKlass on left.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  Node* ldk1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  if (ldk1->Opcode() != Op_LoadKlass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  // Take apart the address of the LoadKlass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  Node* adr1 = ldk1->in(MemNode::Address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  intptr_t con2 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  if (ldk2 == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  if (con2 == oopDesc::klass_offset_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    // We are inspecting an object's concrete class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    // Short-circuit the check if the query is abstract.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    if (superklass->is_interface() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        superklass->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      // Make it come out always false:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
      this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // Check for a LoadKlass from primary supertype array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // Any nested loadklass from loadklass+con must be from the p.s. array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  if (ldk2->Opcode() != Op_LoadKlass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  // Verify that we understand the situation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  if (con2 != (intptr_t) superklass->super_check_offset())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    return NULL;                // Might be element-klass loading from array klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  // If 'superklass' has no subklasses and is not an interface, then we are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  // assured that the only input which will pass the type check is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  // 'superklass' itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  // We could be more liberal here, and allow the optimization on interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  // which have a single implementor.  This would require us to increase the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  // expressiveness of the add_dependency() mechanism.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  // Object arrays must have their base element have no subtypes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  while (superklass->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    ciType* elem = superklass->as_obj_array_klass()->element_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    superklass = elem->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  if (superklass->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    ciInstanceKlass* ik = superklass->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    if (ik->has_subklass() || ik->is_interface())  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    // Add a dependency if there is a chance that a subclass will be added later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
    if (!ik->is_final()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      phase->C->dependencies()->assert_leaf_type(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  // Bypass the dependent load, and compare directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  this->set_req(1,ldk2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
// Simplify an CmpF (compare 2 floats ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
const Type *CmpFNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  // Not constants?  Don't know squat - even if they are the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  // value!  If they are NaN's they compare to LT instead of EQ.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  const TypeF *tf1 = t1->isa_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  const TypeF *tf2 = t2->isa_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  if( !tf1 || !tf2 ) return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  // This implements the Java bytecode fcmpl, so unordered returns -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  if( tf1->is_nan() || tf2->is_nan() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
// Simplify an CmpD (compare 2 doubles ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
const Type *CmpDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  // Not constants?  Don't know squat - even if they are the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  // value!  If they are NaN's they compare to LT instead of EQ.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  const TypeD *td1 = t1->isa_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  const TypeD *td2 = t2->isa_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  if( !td1 || !td2 ) return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  // This implements the Java bytecode dcmpl, so unordered returns -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  if( td1->is_nan() || td2->is_nan() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  if( td1->_d < td2->_d ) return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  if( td1->_d > td2->_d ) return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  assert( td1->_d == td2->_d, "do not understand FP behavior" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  // Check if we can change this to a CmpF and remove a ConvD2F operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  // Change  (CMPD (F2D (float)) (ConD value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  // To      (CMPF      (float)  (ConF value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  // Valid when 'value' does not lose precision as a float.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  // Benefits: eliminates conversion, does not require 24-bit mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  // NaNs prevent commuting operands.  This transform works regardless of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  // order of ConD and ConvF2D inputs by preserving the original order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  int idx_f2d = 1;              // ConvF2D on left side?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  if( in(idx_f2d)->Opcode() != Op_ConvF2D )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    idx_f2d = 2;                // No, swap to check for reversed args
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  int idx_con = 3-idx_f2d;      // Check for the constant on other input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  if( ConvertCmpD2CmpF &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
      in(idx_f2d)->Opcode() == Op_ConvF2D &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      in(idx_con)->Opcode() == Op_ConD ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    double t2_value_as_double = t2->_d;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    float  t2_value_as_float  = (float)t2_value_as_double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    if( t2_value_as_double == (double)t2_value_as_float ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      // Test value can be represented as a float
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
      // Eliminate the conversion to double and create new comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      Node *new_in1 = in(idx_f2d)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
      Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
      if( idx_f2d != 1 ) {      // Must flip args to match original order
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
        Node *tmp = new_in1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
        new_in1 = new_in2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
        new_in2 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
        ? new (phase->C, 3) CmpF3Node( new_in1, new_in2 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
        : new (phase->C, 3) CmpFNode ( new_in1, new_in2 ) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      return new_cmp;           // Changed to CmpFNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    // Testing value required the precision of a double
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  return NULL;                  // No change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
//------------------------------cc2logical-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
// Convert a condition code type to a logical type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
const Type *BoolTest::cc2logical( const Type *CC ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  if( CC == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  const TypeInt *ti = CC->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  if( ti->is_con() ) {          // Only 1 kind of condition codes set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    // Match low order 2 bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    if( _test & 4 ) tmp = 1-tmp;     // Optionally complement result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    return TypeInt::make(tmp);       // Boolean result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  if( CC == TypeInt::CC_GE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    if( _test == ge ) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    if( _test == lt ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  if( CC == TypeInt::CC_LE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    if( _test == le ) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    if( _test == gt ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
//------------------------------dump_spec-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
// Print special per-node info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
void BoolTest::dump_on(outputStream *st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  const char *msg[] = {"eq","gt","??","lt","ne","le","??","ge"};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  st->print(msg[_test]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
uint BoolNode::size_of() const { return sizeof(BoolNode); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
uint BoolNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  const BoolNode *b = (const BoolNode *)&n; // Cast up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  return (_test._test == b->_test._test);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
//------------------------------clone_cmp--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
// Clone a compare/bool tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
static Node *clone_cmp( Node *cmp, Node *cmp1, Node *cmp2, PhaseGVN *gvn, BoolTest::mask test ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  Node *ncmp = cmp->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  ncmp->set_req(1,cmp1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  ncmp->set_req(2,cmp2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  ncmp = gvn->transform( ncmp );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  return new (gvn->C, 2) BoolNode( ncmp, test );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
//-------------------------------make_predicate--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  if (test_value->is_Con())   return test_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  if (test_value->is_Bool())  return test_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  Compile* C = phase->C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  if (test_value->is_CMove() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
      test_value->in(CMoveNode::Condition)->is_Bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
    BoolNode*   bol   = test_value->in(CMoveNode::Condition)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
    const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      return bol;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      return phase->transform( bol->negate(phase) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    // Else fall through.  The CMove gets in the way of the test.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    // It should be the case that make_predicate(bol->as_int_value()) == bol.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  Node* cmp = new (C, 3) CmpINode(test_value, phase->intcon(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  cmp = phase->transform(cmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  Node* bol = new (C, 2) BoolNode(cmp, BoolTest::ne);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  return phase->transform(bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
//--------------------------------as_int_value---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
Node* BoolNode::as_int_value(PhaseGVN* phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  // Inverse to make_predicate.  The CMove probably boils down to a Conv2B.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  Node* cmov = CMoveNode::make(phase->C, NULL, this,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
                               phase->intcon(0), phase->intcon(1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
                               TypeInt::BOOL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  return phase->transform(cmov);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
//----------------------------------negate-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
BoolNode* BoolNode::negate(PhaseGVN* phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  Compile* C = phase->C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  return new (C, 2) BoolNode(in(1), _test.negate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  // This moves the constant to the right.  Helps value-numbering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  Node *cmp = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  if( !cmp->is_Sub() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  int cop = cmp->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  if( cop == Op_FastLock || cop == Op_FastUnlock ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  Node *cmp1 = cmp->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  Node *cmp2 = cmp->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  if( !cmp1 ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  // Constant on left?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  Node *con = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  uint op2 = cmp2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  // Move constants to the right of compare's to canonicalize.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  // Do not muck with Opaque1 nodes, as this indicates a loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  // guard that cannot change shape.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
  if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
      // Because of NaN's, CmpD and CmpF are not commutative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      cop != Op_CmpD && cop != Op_CmpF &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      // Protect against swapping inputs to a compare when it is used by a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
      // counted loop exit, which requires maintaining the loop-limit as in(2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
      !is_counted_loop_exit_test() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    // Ok, commute the constant to the right of the cmp node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
    // Clone the Node, getting a new Node of the same class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    cmp = cmp->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    // Swap inputs to the clone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    cmp->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    cmp = phase->transform( cmp );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    return new (phase->C, 2) BoolNode( cmp, _test.commute() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  // The XOR-1 is an idiom used to flip the sense of a bool.  We flip the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  // test instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  int cmp1_op = cmp1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  const TypeInt* cmp2_type = phase->type(cmp2)->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  if (cmp2_type == NULL)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  Node* j_xor = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  if( cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
      cmp1_op == Op_XorI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      j_xor->in(1) != j_xor &&          // An xor of itself is dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
      phase->type( j_xor->in(2) ) == TypeInt::ONE &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      (_test._test == BoolTest::eq ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
       _test._test == BoolTest::ne) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    Node *ncmp = phase->transform(new (phase->C, 3) CmpINode(j_xor->in(1),cmp2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    return new (phase->C, 2) BoolNode( ncmp, _test.negate() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  // This is a standard idiom for branching on a boolean value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  Node *c2b = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  if( cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      cmp1_op == Op_Conv2B &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      (_test._test == BoolTest::eq ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
       _test._test == BoolTest::ne) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
       ? (Node*)new (phase->C, 3) CmpINode(c2b->in(1),cmp2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
       : (Node*)new (phase->C, 3) CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    return new (phase->C, 2) BoolNode( ncmp, _test._test );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  // Comparing a SubI against a zero is equal to comparing the SubI
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  // arguments directly.  This only works for eq and ne comparisons
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  // due to possible integer overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
        (cop == Op_CmpI) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
        (cmp1->Opcode() == Op_SubI) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
        ( cmp2_type == TypeInt::ZERO ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    Node *ncmp = phase->transform( new (phase->C, 3) CmpINode(cmp1->in(1),cmp1->in(2)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    return new (phase->C, 2) BoolNode( ncmp, _test._test );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  // Change (-A vs 0) into (A vs 0) by commuting the test.  Disallow in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  // most general case because negating 0x80000000 does nothing.  Needed for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  // the CmpF3/SubI/CmpI idiom.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  if( cop == Op_CmpI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      cmp1->Opcode() == Op_SubI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
      phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
      phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    Node *ncmp = phase->transform( new (phase->C, 3) CmpINode(cmp1->in(2),cmp2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
    return new (phase->C, 2) BoolNode( ncmp, _test.commute() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  //  The transformation below is not valid for either signed or unsigned
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  //  comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  //  This transformation can be resurrected when we are able to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  //  make inferences about the range of values being subtracted from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  //  (or added to) relative to the wraparound point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  //    // Remove +/-1's if possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  //    // "X <= Y-1" becomes "X <  Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  //    // "X+1 <= Y" becomes "X <  Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
  //    // "X <  Y+1" becomes "X <= Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  //    // "X-1 <  Y" becomes "X <= Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  //    // Do not this to compares off of the counted-loop-end.  These guys are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  //    // checking the trip counter and they want to use the post-incremented
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  //    // counter.  If they use the PRE-incremented counter, then the counter has
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  //    // to be incremented in a private block on a loop backedge.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  //    if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  //      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
  //  #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  //    // Do not do this in a wash GVN pass during verification.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  //    // Gets triggered by too many simple optimizations to be bothered with
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  //    // re-trying it again and again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  //    if( !phase->allow_progress() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  //  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  //    // Not valid for unsigned compare because of corner cases in involving zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
  //    // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  //    // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  //    // "0 <=u Y" is always true).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
  //    if( cmp->Opcode() == Op_CmpU ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  //    int cmp2_op = cmp2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  //    if( _test._test == BoolTest::le ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  //      if( cmp1_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
  //      else if( cmp2_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  //    } else if( _test._test == BoolTest::lt ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  //      if( cmp1_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  //      else if( cmp2_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
// Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
// based on local information.   If the input is constant, do it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
const Type *BoolNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  return _test.cc2logical( phase->type( in(1) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
//------------------------------dump_spec--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
// Dump special per-node info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
void BoolNode::dump_spec(outputStream *st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  st->print("[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  _test.dump_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  st->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
//------------------------------is_counted_loop_exit_test--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
// Returns true if node is used by a counted loop node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
bool BoolNode::is_counted_loop_exit_test() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    Node* use = fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    if (use->is_CountedLoopEnd()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
//------------------------------NegNode----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
Node *NegFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  if( in(1)->Opcode() == Op_SubF )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    return new (phase->C, 3) SubFNode( in(1)->in(2), in(1)->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
Node *NegDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  if( in(1)->Opcode() == Op_SubD )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    return new (phase->C, 3) SubDNode( in(1)->in(2), in(1)->in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
// Compute sqrt
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
const Type *SqrtDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  return TypeD::make( sqrt( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
// Compute cos
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
const Type *CosDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  return TypeD::make( SharedRuntime::dcos( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
// Compute sin
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
const Type *SinDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  return TypeD::make( SharedRuntime::dsin( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
// Compute tan
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
const Type *TanDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  return TypeD::make( SharedRuntime::dtan( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
// Compute log
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
const Type *LogDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  return TypeD::make( SharedRuntime::dlog( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
// Compute log10
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
const Type *Log10DNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  return TypeD::make( SharedRuntime::dlog10( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
// Compute exp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
const Type *ExpDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  return TypeD::make( SharedRuntime::dexp( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
// Compute pow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
const Type *PowDNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
  if( t2->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
  double d1 = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
  double d2 = t2->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
  if( d1 < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  if( d2 < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
  return TypeD::make( SharedRuntime::dpow( d1, d2 ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
}