hotspot/src/share/vm/opto/connode.cpp
author roland
Tue, 09 Oct 2012 10:11:38 +0200
changeset 13969 d2a189b83b87
parent 13895 f6dfe4123709
child 16670 4af09aff4237
permissions -rw-r--r--
7054512: Compress class pointers after perm gen removal Summary: support of compress class pointers in the compilers. Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11959
0bf55e106849 7146442: assert(false) failed: bad AD file
kvn
parents: 10739
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3914
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3914
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3914
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
#include "opto/addnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    28
#include "opto/compile.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    29
#include "opto/connode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
#include "opto/machnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    31
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    32
#include "opto/memnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    33
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    34
#include "opto/subnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    35
#include "runtime/sharedRuntime.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    37
// Optimization - Graph Style
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//------------------------------hash-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
uint ConNode::hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  return (uintptr_t)in(TypeFunc::Control) + _type->hash();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//------------------------------make-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
ConNode *ConNode::make( Compile* C, const Type *t ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  switch( t->basic_type() ) {
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    48
  case T_INT:         return new (C) ConINode( t->is_int() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    49
  case T_LONG:        return new (C) ConLNode( t->is_long() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    50
  case T_FLOAT:       return new (C) ConFNode( t->is_float_constant() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    51
  case T_DOUBLE:      return new (C) ConDNode( t->is_double_constant() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    52
  case T_VOID:        return new (C) ConNode ( Type::TOP );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    53
  case T_OBJECT:      return new (C) ConPNode( t->is_ptr() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    54
  case T_ARRAY:       return new (C) ConPNode( t->is_aryptr() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    55
  case T_ADDRESS:     return new (C) ConPNode( t->is_ptr() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    56
  case T_NARROWOOP:   return new (C) ConNNode( t->is_narrowoop() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    57
  case T_NARROWKLASS: return new (C) ConNKlassNode( t->is_narrowklass() );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
    58
  case T_METADATA:    return new (C) ConPNode( t->is_ptr() );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    // Expected cases:  TypePtr::NULL_PTR, any is_rawptr()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    // Also seen: AnyPtr(TopPTR *+top); from command line:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    //   r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // %%%% Stop using TypePtr::NULL_PTR to represent nulls:  use either TypeRawPtr::NULL_PTR
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    // or else TypeOopPtr::NULL_PTR.  Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
The major change is for CMoveP and StrComp.  They have related but slightly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
different problems.  They both take in TWO oops which are both null-checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
independently before the using Node.  After CCP removes the CastPP's they need
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
to pick up the guarding test edge - in this case TWO control edges.  I tried
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
various solutions, all have problems:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
(1) Do nothing.  This leads to a bug where we hoist a Load from a CMoveP or a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
StrComp above a guarding null check.  I've seen both cases in normal -Xcomp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
testing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
(2) Plug the control edge from 1 of the 2 oops in.  Apparent problem here is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
to figure out which test post-dominates.  The real problem is that it doesn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
matter which one you pick.  After you pick up, the dominating-test elider in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
IGVN can remove the test and allow you to hoist up to the dominating test on
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1400
diff changeset
    85
the chosen oop bypassing the test on the not-chosen oop.  Seen in testing.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
Oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
(3) Leave the CastPP's in.  This makes the graph more accurate in some sense;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
we get to keep around the knowledge that an oop is not-null after some test.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
Alas, the CastPP's interfere with GVN (some values are the regular oop, some
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
This cost us 10% on SpecJVM, even when I removed some of the more trivial
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
cases in the optimizer.  Removing more useless Phi's started allowing Loads to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
illegally float above null checks.  I gave up on this approach.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
(4) Add BOTH control edges to both tests.  Alas, too much code knows that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
control edges are in slot-zero ONLY.  Many quick asserts fail; no way to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
this one.  Note that I really want to allow the CMoveP to float and add both
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
control edges to the dependent Load op - meaning I can select early but I
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
cannot Load until I pass both tests.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
(5) Do not hoist CMoveP and StrComp.  To this end I added the v-call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
depends_only_on_test().  No obvious performance loss on Spec, but we are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
clearly conservative on CMoveP (also so on StrComp but that's unlikely to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
matter ever).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// Return a node which is more "ideal" than the current node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// Move constants to the right.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
1067
f82e0a8cd438 6736417: Fastdebug C2 crashes in StoreBNode::Ideal
kvn
parents: 781
diff changeset
   115
  // Don't bother trying to transform a dead node
f82e0a8cd438 6736417: Fastdebug C2 crashes in StoreBNode::Ideal
kvn
parents: 781
diff changeset
   116
  if( in(0) && in(0)->is_top() )  return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  assert( !phase->eqv(in(Condition), this) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
          !phase->eqv(in(IfFalse), this) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
          !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  if( phase->type(in(Condition)) == Type::TOP )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return NULL; // return NULL when Condition is dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    if( in(Condition)->is_Bool() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      BoolNode* b  = in(Condition)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      BoolNode* b2 = b->negate(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
//------------------------------is_cmove_id------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// Helper function to check for CMOVE identity.  Shared with PhiNode::Identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Check for Cmp'ing and CMove'ing same values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  if( (phase->eqv(cmp->in(1),f) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
       phase->eqv(cmp->in(2),t)) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      // Swapped Cmp is OK
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      (phase->eqv(cmp->in(2),f) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
       phase->eqv(cmp->in(1),t)) ) {
2745
60853c6a93b7 6833879: Assigning positive zero is ignored when old value is negative zero
cfang
parents: 2254
diff changeset
   142
    // Give up this identity check for floating points because it may choose incorrect
60853c6a93b7 6833879: Assigning positive zero is ignored when old value is negative zero
cfang
parents: 2254
diff changeset
   143
    // value around 0.0 and -0.0
60853c6a93b7 6833879: Assigning positive zero is ignored when old value is negative zero
cfang
parents: 2254
diff changeset
   144
    if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
60853c6a93b7 6833879: Assigning positive zero is ignored when old value is negative zero
cfang
parents: 2254
diff changeset
   145
      return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    // Check for "(t==f)?t:f;" and replace with "f"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    if( b->_test._test == BoolTest::eq )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      return f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    // Allow the inverted case as well
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    // Check for "(t!=f)?t:f;" and replace with "t"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    if( b->_test._test == BoolTest::ne )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// Conditional-move is an identity if both inputs are the same, or the test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// true or false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
Node *CMoveNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    return in(IfFalse);         // Then it doesn't matter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  if( phase->type(in(Condition)) == TypeInt::ZERO )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    return in(IfFalse);         // Always pick left(false) input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if( phase->type(in(Condition)) == TypeInt::ONE )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return in(IfTrue);          // Always pick right(true) input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Check for CMove'ing a constant after comparing against the constant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Happens all the time now, since if we compare equality vs a constant in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // the parser, we "know" the variable is constant on one path and we force
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // it.  Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // conditional move: "x = (x==0)?0:x;".  Yucko.  This fix is slightly more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // general in that we don't need constants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  if( in(Condition)->is_Bool() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    BoolNode *b = in(Condition)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    Node *cmp = b->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    if( cmp->is_Cmp() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      if( id ) return id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
// Result is the meet of inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
const Type *CMoveNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  if( phase->type(in(Condition)) == Type::TOP )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  return phase->type(in(IfFalse))->meet(phase->type(in(IfTrue)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
//------------------------------make-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// Make a correctly-flavored CMove.  Since _type is directly determined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
// from the inputs we do not need to specify it here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
CMoveNode *CMoveNode::make( Compile *C, Node *c, Node *bol, Node *left, Node *right, const Type *t ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  switch( t->basic_type() ) {
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   199
  case T_INT:     return new (C) CMoveINode( bol, left, right, t->is_int() );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   200
  case T_FLOAT:   return new (C) CMoveFNode( bol, left, right, t );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   201
  case T_DOUBLE:  return new (C) CMoveDNode( bol, left, right, t );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   202
  case T_LONG:    return new (C) CMoveLNode( bol, left, right, t->is_long() );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   203
  case T_OBJECT:  return new (C) CMovePNode( c, bol, left, right, t->is_oopptr() );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   204
  case T_ADDRESS: return new (C) CMovePNode( c, bol, left, right, t->is_ptr() );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   205
  case T_NARROWOOP: return new (C) CMoveNNode( c, bol, left, right, t );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// Return a node which is more "ideal" than the current node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
// Check for conversions to boolean
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Try generic ideal's first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  Node *x = CMoveNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if( x ) return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // If zero is on the left (false-case, no-move-case) it must mean another
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // constant is on the right (otherwise the shared CMove::Ideal code would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  // have moved the constant to the right).  This situation is bad for Intel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // and a don't-care for Sparc.  It's bad for Intel because the zero has to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // be manifested in a register with a XOR which kills flags, which are live
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // on input to the CMoveI, leading to a situation which causes excessive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // spilling on Intel.  For Sparc, if the zero in on the left the Sparc will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // zero a register via G0 and conditionally-move the other constant.  If the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // zero is on the right, the Sparc will load the first constant with a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // 13-bit set-lo and conditionally move G0.  See bug 4677505.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    if( in(Condition)->is_Bool() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      BoolNode* b  = in(Condition)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      BoolNode* b2 = b->negate(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      return make( phase->C, in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Now check for booleans
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  int flip = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Check for picking from zero/one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    flip = 1 - flip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  } else return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Check for eq/ne test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if( !in(1)->is_Bool() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  BoolNode *bol = in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if( bol->_test._test == BoolTest::eq ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  } else if( bol->_test._test == BoolTest::ne ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    flip = 1-flip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  } else return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // Check for vs 0 or 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  if( !bol->in(1)->is_Cmp() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  const CmpNode *cmp = bol->in(1)->as_Cmp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    // Allow cmp-vs-1 if the other input is bounded by 0-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    if( phase->type(cmp->in(1)) != TypeInt::BOOL )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    flip = 1 - flip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  } else return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // Convert to a bool (flipped)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // Build int->bool conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  if( PrintOpto ) tty->print_cr("CMOV to I2B");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
#endif
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   272
  Node *n = new (phase->C) Conv2BNode( cmp->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  if( flip )
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   274
    n = new (phase->C) XorINode( phase->transform(n), phase->intcon(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
// Return a node which is more "ideal" than the current node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
// Check for absolute value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Try generic ideal's first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  Node *x = CMoveNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  if( x ) return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  int  phi_x_idx = 0;           // Index of phi input where to find naked x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  // Find the Bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  if( !in(1)->is_Bool() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  BoolNode *bol = in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // Check bool sense
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  switch( bol->_test._test ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  default:           return NULL;                           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // Find zero input of CmpF; the other input is being abs'd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  Node *cmpf = bol->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  if( cmpf->Opcode() != Op_CmpF ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  Node *X = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  bool flip = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    X = cmpf->in(3 - cmp_zero_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    // The test is inverted, we should invert the result...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    X = cmpf->in(cmp_zero_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    flip = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // If X is found on the appropriate phi input, find the subtract on the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if( X != in(phi_x_idx) ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  Node *sub = in(phi_sub_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  // Allow only SubF(0,X) and fail out for all others; NegF is not OK
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if( sub->Opcode() != Op_SubF ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      sub->in(2) != X ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   328
  Node *abs = new (phase->C) AbsFNode( X );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if( flip )
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   330
    abs = new (phase->C) SubFNode(sub->in(1), phase->transform(abs));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  return abs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
// Return a node which is more "ideal" than the current node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
// Check for absolute value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // Try generic ideal's first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  Node *x = CMoveNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  if( x ) return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  int  phi_x_idx = 0;           // Index of phi input where to find naked x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  // Find the Bool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  if( !in(1)->is_Bool() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  BoolNode *bol = in(1)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // Check bool sense
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  switch( bol->_test._test ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  default:           return NULL;                           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  // Find zero input of CmpD; the other input is being abs'd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  Node *cmpd = bol->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  if( cmpd->Opcode() != Op_CmpD ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  Node *X = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  bool flip = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    X = cmpd->in(3 - cmp_zero_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // The test is inverted, we should invert the result...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    X = cmpd->in(cmp_zero_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    flip = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  // If X is found on the appropriate phi input, find the subtract on the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if( X != in(phi_x_idx) ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  Node *sub = in(phi_sub_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // Allow only SubD(0,X) and fail out for all others; NegD is not OK
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  if( sub->Opcode() != Op_SubD ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      sub->in(2) != X ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   384
  Node *abs = new (phase->C) AbsDNode( X );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  if( flip )
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
   386
    abs = new (phase->C) SubDNode(sub->in(1), phase->transform(abs));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  return abs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
// If input is already higher or equal to cast type, then this is an identity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
Node *ConstraintCastNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  return phase->type(in(1))->higher_equal(_type) ? in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
// Take 'join' of input and cast-up type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
const Type *ConstraintCastNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  const Type* ft = phase->type(in(1))->filter(_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // Previous versions of this function had some special case logic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  // which is no longer necessary.  Make sure of the required effects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  switch (Opcode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  case Op_CastII:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      const Type* t1 = phase->type(in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      if( t1 == Type::TOP )  assert(ft == Type::TOP, "special case #1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      const Type* rt = t1->join(_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      if (rt->empty())       assert(ft == Type::TOP, "special case #2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  case Op_CastPP:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    if (phase->type(in(1)) == TypePtr::NULL_PTR &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        _type->isa_ptr() && _type->is_ptr()->_ptr == TypePtr::NotNull)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      assert(ft == Type::TOP, "special case #3");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
#endif //ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  return ft;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// Return a node which is more "ideal" than the current node.  Strip out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// control copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
Node *ConstraintCastNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
//------------------------------Ideal_DU_postCCP-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
// Throw away cast after constant propagation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
Node *ConstraintCastNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  const Type *t = ccp->type(in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  ccp->hash_delete(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  set_type(t);                   // Turn into ID function
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  ccp->hash_insert(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
//------------------------------Ideal_DU_postCCP-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
// If not converting int->oop, throw away cast after constant propagation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
Node *CastPPNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  const Type *t = ccp->type(in(1));
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   451
  if (!t->isa_oop_ptr() || ((in(1)->is_DecodeN()) && Matcher::gen_narrow_oop_implicit_null_checks())) {
1400
afd034bb8c2e 6747051: Improve code and implicit null check generation for compressed oops
kvn
parents: 1067
diff changeset
   452
    return NULL; // do not transform raw pointers or narrow oops
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  return ConstraintCastNode::Ideal_DU_postCCP(ccp);
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
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// If input is already higher or equal to cast type, then this is an identity.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
Node *CheckCastPPNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  // Toned down to rescue meeting at a Phi 3 different oops all implementing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  // the same interface.  CompileTheWorld starting at 502, kd12rc1.zip.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  return (phase->type(in(1)) == phase->type(this)) ? in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
// Determine whether "n" is a node which can cause an alias of one of its inputs.  Node types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
// which can create aliases are: CheckCastPP, Phi, and any store (if there is also a load from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
// the location.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
// Note:  this checks for aliases created in this compilation, not ones which may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
//        be potentially created at call sites.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
static bool can_cause_alias(Node *n, PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  bool possible_alias = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  if (n->is_Store()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    possible_alias = !n->as_Store()->value_never_loaded(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    int opc = n->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    possible_alias = n->is_Phi() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
        opc == Op_CheckCastPP ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
        opc == Op_StorePConditional ||
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   483
        opc == Op_CompareAndSwapP ||
13886
8d82c4dfa722 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 13728
diff changeset
   484
        opc == Op_CompareAndSwapN ||
8d82c4dfa722 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 13728
diff changeset
   485
        opc == Op_GetAndSetP ||
8d82c4dfa722 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()
roland
parents: 13728
diff changeset
   486
        opc == Op_GetAndSetN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  return possible_alias;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
// Take 'join' of input and cast-up type, unless working with an Interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
const Type *CheckCastPPNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  if( in(0) && phase->type(in(0)) == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  const Type *inn = phase->type(in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if( inn == Type::TOP ) return Type::TOP;  // No information yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  const TypePtr *in_type   = inn->isa_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  const TypePtr *my_type   = _type->isa_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  const Type *result = _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  if( in_type != NULL && my_type != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    TypePtr::PTR   in_ptr    = in_type->ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    if( in_ptr == TypePtr::Null ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
      result = in_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    } else if( in_ptr == TypePtr::Constant ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      // Casting a constant oop to an interface?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      // (i.e., a String to a Comparable?)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
      // Then return the interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      const TypeOopPtr *jptr = my_type->isa_oopptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      assert( jptr, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
      result =  (jptr->klass()->is_interface() || !in_type->higher_equal(_type))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        ? my_type->cast_to_ptr_type( TypePtr::NotNull )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
        : in_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
      result =  my_type->cast_to_ptr_type( my_type->join_ptr(in_ptr) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // JOIN NOT DONE HERE BECAUSE OF INTERFACE ISSUES.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  // FIX THIS (DO THE JOIN) WHEN UNION TYPES APPEAR!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  // Remove this code after overnight run indicates no performance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  // loss from not performing JOIN at CheckCastPPNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // const TypeInstPtr *in_oop = in->isa_instptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  // const TypeInstPtr *my_oop = _type->isa_instptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  // // If either input is an 'interface', return destination type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  // assert (in_oop == NULL || in_oop->klass() != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  // assert (my_oop == NULL || my_oop->klass() != NULL, "");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11959
diff changeset
   533
  // if( (in_oop && in_oop->klass()->is_interface())
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11959
diff changeset
   534
  //   ||(my_oop && my_oop->klass()->is_interface()) ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  //   TypePtr::PTR  in_ptr = in->isa_ptr() ? in->is_ptr()->_ptr : TypePtr::BotPTR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  //   // Preserve cast away nullness for interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  //   if( in_ptr == TypePtr::NotNull && my_oop && my_oop->_ptr == TypePtr::BotPTR ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  //     return my_oop->cast_to_ptr_type(TypePtr::NotNull);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  //   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  //   return _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // // Neither the input nor the destination type is an interface,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // // history: JOIN used to cause weird corner case bugs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  // //          return (in == TypeOopPtr::NULL_PTR) ? in : _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  // // JOIN picks up NotNull in common instance-of/check-cast idioms, both oops.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // // JOIN does not preserve NotNull in other cases, e.g. RawPtr vs InstPtr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  // const Type *join = in->join(_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  // // Check if join preserved NotNull'ness for pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  // if( join->isa_ptr() && _type->isa_ptr() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  //   TypePtr::PTR join_ptr = join->is_ptr()->_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  //   TypePtr::PTR type_ptr = _type->is_ptr()->_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  //   // If there isn't any NotNull'ness to preserve
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  //   // OR if join preserved NotNull'ness then return it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  //   if( type_ptr == TypePtr::BotPTR  || type_ptr == TypePtr::Null ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  //       join_ptr == TypePtr::NotNull || join_ptr == TypePtr::Constant ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  //     return join;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  //   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  //   // ELSE return same old type as before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  //   return _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  // // Not joining two pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  // return join;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
// Return a node which is more "ideal" than the current node.  Strip out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
// control copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
Node *CheckCastPPNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   574
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   575
Node* DecodeNNode::Identity(PhaseTransform* phase) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   576
  const Type *t = phase->type( in(1) );
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   577
  if( t == Type::TOP ) return in(1);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   578
594
9f4474e5dbaf 6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents: 590
diff changeset
   579
  if (in(1)->is_EncodeP()) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   580
    // (DecodeN (EncodeP p)) -> p
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   581
    return in(1)->in(1);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   582
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   583
  return this;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   584
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   585
371
1aacedc9db7c 6689060: Escape Analysis does not work with Compressed Oops
kvn
parents: 360
diff changeset
   586
const Type *DecodeNNode::Value( PhaseTransform *phase ) const {
762
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   587
  const Type *t = phase->type( in(1) );
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   588
  if (t == Type::TOP) return Type::TOP;
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   589
  if (t == TypeNarrowOop::NULL_PTR) return TypePtr::NULL_PTR;
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   590
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   591
  assert(t->isa_narrowoop(), "only  narrowoop here");
767
64fb1fd7186d 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 762
diff changeset
   592
  return t->make_ptr();
371
1aacedc9db7c 6689060: Escape Analysis does not work with Compressed Oops
kvn
parents: 360
diff changeset
   593
}
1aacedc9db7c 6689060: Escape Analysis does not work with Compressed Oops
kvn
parents: 360
diff changeset
   594
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   595
Node* EncodePNode::Identity(PhaseTransform* phase) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   596
  const Type *t = phase->type( in(1) );
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   597
  if( t == Type::TOP ) return in(1);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   598
594
9f4474e5dbaf 6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents: 590
diff changeset
   599
  if (in(1)->is_DecodeN()) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   600
    // (EncodeP (DecodeN p)) -> p
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   601
    return in(1)->in(1);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   602
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   603
  return this;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   604
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   605
371
1aacedc9db7c 6689060: Escape Analysis does not work with Compressed Oops
kvn
parents: 360
diff changeset
   606
const Type *EncodePNode::Value( PhaseTransform *phase ) const {
762
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   607
  const Type *t = phase->type( in(1) );
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   608
  if (t == Type::TOP) return Type::TOP;
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   609
  if (t == TypePtr::NULL_PTR) return TypeNarrowOop::NULL_PTR;
1b26adb5fea1 6715633: when matching a memory node the adr_type should not change
kvn
parents: 594
diff changeset
   610
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   611
  assert(t->isa_oop_ptr(), "only oopptr here");
767
64fb1fd7186d 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 762
diff changeset
   612
  return t->make_narrowoop();
371
1aacedc9db7c 6689060: Escape Analysis does not work with Compressed Oops
kvn
parents: 360
diff changeset
   613
}
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   614
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   615
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   616
Node *EncodeNarrowPtrNode::Ideal_DU_postCCP( PhaseCCP *ccp ) {
589
a44a1e70a3e4 6695810: null oop passed to encode_heap_oop_not_null
kvn
parents: 371
diff changeset
   617
  return MemNode::Ideal_common_DU_postCCP(ccp, this, in(1));
a44a1e70a3e4 6695810: null oop passed to encode_heap_oop_not_null
kvn
parents: 371
diff changeset
   618
}
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 209
diff changeset
   619
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   620
Node* DecodeNKlassNode::Identity(PhaseTransform* phase) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   621
  const Type *t = phase->type( in(1) );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   622
  if( t == Type::TOP ) return in(1);
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   623
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   624
  if (in(1)->is_EncodePKlass()) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   625
    // (DecodeNKlass (EncodePKlass p)) -> p
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   626
    return in(1)->in(1);
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   627
  }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   628
  return this;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   629
}
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   630
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   631
const Type *DecodeNKlassNode::Value( PhaseTransform *phase ) const {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   632
  const Type *t = phase->type( in(1) );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   633
  if (t == Type::TOP) return Type::TOP;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   634
  assert(t != TypeNarrowKlass::NULL_PTR, "null klass?");
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   635
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   636
  assert(t->isa_narrowklass(), "only narrow klass ptr here");
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   637
  return t->make_ptr();
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   638
}
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   639
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   640
Node* EncodePKlassNode::Identity(PhaseTransform* phase) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   641
  const Type *t = phase->type( in(1) );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   642
  if( t == Type::TOP ) return in(1);
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   643
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   644
  if (in(1)->is_DecodeNKlass()) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   645
    // (EncodePKlass (DecodeNKlass p)) -> p
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   646
    return in(1)->in(1);
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   647
  }
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   648
  return this;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   649
}
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   650
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   651
const Type *EncodePKlassNode::Value( PhaseTransform *phase ) const {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   652
  const Type *t = phase->type( in(1) );
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   653
  if (t == Type::TOP) return Type::TOP;
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   654
  assert (t != TypePtr::NULL_PTR, "null klass?");
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   655
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   656
  assert(UseCompressedKlassPointers && t->isa_klassptr(), "only klass ptr here");
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   657
  return t->make_narrowklass();
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   658
}
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   659
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   660
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
Node *Conv2BNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  if( t == Type::TOP ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  if( t == TypeInt::ZERO ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  if( t == TypeInt::ONE ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  if( t == TypeInt::BOOL ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
const Type *Conv2BNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  if( t == TypeInt::ZERO ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  if( t == TypePtr::NULL_PTR ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  const TypePtr *tp = t->isa_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  if( tp != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    if( tp->ptr() == TypePtr::AnyNull ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    if( tp->ptr() == TypePtr::Constant) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    if (tp->ptr() == TypePtr::NotNull)  return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  if (t->base() != Type::Int) return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  const TypeInt *ti = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  if( ti->_hi < 0 || ti->_lo > 0 ) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
// The conversions operations are all Alpha sorted.  Please keep it that way!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
const Type *ConvD2FNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  if( t == Type::DOUBLE ) return Type::FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  const TypeD *td = t->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  return TypeF::make( (float)td->getd() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
// Float's can be converted to doubles with no loss of bits.  Hence
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
// converting a float to a double and back to a float is a NOP.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
Node *ConvD2FNode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  return (in(1)->Opcode() == Op_ConvF2D) ? in(1)->in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
const Type *ConvD2INode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  if( t == Type::DOUBLE ) return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  const TypeD *td = t->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  return TypeInt::make( SharedRuntime::d2i( td->getd() ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
// If converting to an int type, skip any rounding nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
Node *ConvD2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  if( in(1)->Opcode() == Op_RoundDouble )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    set_req(1,in(1)->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
// Int's can be converted to doubles with no loss of bits.  Hence
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
// converting an integer to a double and back to an integer is a NOP.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
Node *ConvD2INode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  return (in(1)->Opcode() == Op_ConvI2D) ? in(1)->in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
const Type *ConvD2LNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  if( t == Type::DOUBLE ) return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  const TypeD *td = t->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  return TypeLong::make( SharedRuntime::d2l( td->getd() ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
Node *ConvD2LNode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  // Remove ConvD2L->ConvL2D->ConvD2L sequences.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  if( in(1)       ->Opcode() == Op_ConvL2D &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
      in(1)->in(1)->Opcode() == Op_ConvD2L )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
// If converting to an int type, skip any rounding nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
Node *ConvD2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  if( in(1)->Opcode() == Op_RoundDouble )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    set_req(1,in(1)->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
const Type *ConvF2DNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  if( t == Type::FLOAT ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  const TypeF *tf = t->is_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  return TypeD::make( (double)tf->getf() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
const Type *ConvF2INode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  if( t == Type::TOP )       return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  if( t == Type::FLOAT ) return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  const TypeF *tf = t->is_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  return TypeInt::make( SharedRuntime::f2i( tf->getf() ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
Node *ConvF2INode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  // Remove ConvF2I->ConvI2F->ConvF2I sequences.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  if( in(1)       ->Opcode() == Op_ConvI2F &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
      in(1)->in(1)->Opcode() == Op_ConvF2I )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
// If converting to an int type, skip any rounding nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
Node *ConvF2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  if( in(1)->Opcode() == Op_RoundFloat )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    set_req(1,in(1)->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
const Type *ConvF2LNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  if( t == Type::TOP )       return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  if( t == Type::FLOAT ) return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  const TypeF *tf = t->is_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  return TypeLong::make( SharedRuntime::f2l( tf->getf() ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
Node *ConvF2LNode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  // Remove ConvF2L->ConvL2F->ConvF2L sequences.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  if( in(1)       ->Opcode() == Op_ConvL2F &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
      in(1)->in(1)->Opcode() == Op_ConvF2L )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
// If converting to an int type, skip any rounding nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
Node *ConvF2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  if( in(1)->Opcode() == Op_RoundFloat )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    set_req(1,in(1)->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
const Type *ConvI2DNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  const TypeInt *ti = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  if( ti->is_con() ) return TypeD::make( (double)ti->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
const Type *ConvI2FNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  const TypeInt *ti = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  if( ti->is_con() ) return TypeF::make( (float)ti->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
Node *ConvI2FNode::Identity(PhaseTransform *phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  // Remove ConvI2F->ConvF2I->ConvI2F sequences.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  if( in(1)       ->Opcode() == Op_ConvF2I &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      in(1)->in(1)->Opcode() == Op_ConvI2F )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
const Type *ConvI2LNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  const TypeInt *ti = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  const Type* tl = TypeLong::make(ti->_lo, ti->_hi, ti->_widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  // Join my declared type against my incoming type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  tl = tl->filter(_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  return tl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
static inline bool long_ranges_overlap(jlong lo1, jlong hi1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
                                       jlong lo2, jlong hi2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  // Two ranges overlap iff one range's low point falls in the other range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  return (lo2 <= lo1 && lo1 <= hi2) || (lo1 <= lo2 && lo2 <= hi1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
Node *ConvI2LNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  const TypeLong* this_type = this->type()->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  Node* this_changed = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  // If _major_progress, then more loop optimizations follow.  Do NOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  // remove this node's type assertion until no more loop ops can happen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  // The progress bit is set in the major loop optimizations THEN comes the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  // call to IterGVN and any chance of hitting this code.  Cf. Opaque1Node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  if (can_reshape && !phase->C->major_progress()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
    const TypeInt* in_type = phase->type(in(1))->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    if (in_type != NULL && this_type != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
        (in_type->_lo != this_type->_lo ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
         in_type->_hi != this_type->_hi)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
      // Although this WORSENS the type, it increases GVN opportunities,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
      // because I2L nodes with the same input will common up, regardless
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
      // of slightly differing type assertions.  Such slight differences
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
      // arise routinely as a result of loop unrolling, so this is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
      // post-unrolling graph cleanup.  Choose a type which depends only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
      // on my input.  (Exception:  Keep a range assertion of >=0 or <0.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
      jlong lo1 = this_type->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
      jlong hi1 = this_type->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
      int   w1  = this_type->_widen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      if (lo1 != (jint)lo1 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
          hi1 != (jint)hi1 ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
          lo1 > hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
        // Overflow leads to wraparound, wraparound leads to range saturation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
        lo1 = min_jint; hi1 = max_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
      } else if (lo1 >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
        // Keep a range assertion of >=0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
        lo1 = 0;        hi1 = max_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
      } else if (hi1 < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
        // Keep a range assertion of <0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
        lo1 = min_jint; hi1 = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
        lo1 = min_jint; hi1 = max_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      const TypeLong* wtype = TypeLong::make(MAX2((jlong)in_type->_lo, lo1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
                                             MIN2((jlong)in_type->_hi, hi1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
                                             MAX2((int)in_type->_widen, w1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
      if (wtype != type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
        set_type(wtype);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
        // Note: this_type still has old type value, for the logic below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
        this_changed = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  // Convert ConvI2L(AddI(x, y)) to AddL(ConvI2L(x), ConvI2L(y)) ,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  // but only if x and y have subranges that cannot cause 32-bit overflow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  // under the assumption that x+y is in my own subrange this->type().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  // This assumption is based on a constraint (i.e., type assertion)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  // established in Parse::array_addressing or perhaps elsewhere.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  // This constraint has been adjoined to the "natural" type of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  // the incoming argument in(0).  We know (because of runtime
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  // checks) - that the result value I2L(x+y) is in the joined range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  // Hence we can restrict the incoming terms (x, y) to values such
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  // that their sum also lands in that range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  // This optimization is useful only on 64-bit systems, where we hope
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  // the addition will end up subsumed in an addressing mode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  // It is necessary to do this when optimizing an unrolled array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  // copy loop such as x[i++] = y[i++].
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  // On 32-bit systems, it's better to perform as much 32-bit math as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  // possible before the I2L conversion, because 32-bit math is cheaper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  // There's no common reason to "leak" a constant offset through the I2L.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  // Addressing arithmetic will not absorb it as part of a 64-bit AddL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  Node* z = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  int op = z->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  if (op == Op_AddI || op == Op_SubI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    Node* x = z->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    Node* y = z->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    assert (x != z && y != z, "dead loop in ConvI2LNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    if (phase->type(x) == Type::TOP)  return this_changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    if (phase->type(y) == Type::TOP)  return this_changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    const TypeInt*  tx = phase->type(x)->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    const TypeInt*  ty = phase->type(y)->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    const TypeLong* tz = this_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    jlong xlo = tx->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    jlong xhi = tx->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
    jlong ylo = ty->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    jlong yhi = ty->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    jlong zlo = tz->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    jlong zhi = tz->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    jlong vbit = CONST64(1) << BitsPerInt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    int widen =  MAX2(tx->_widen, ty->_widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    if (op == Op_SubI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
      jlong ylo0 = ylo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
      ylo = -yhi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      yhi = -ylo0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    // See if x+y can cause positive overflow into z+2**32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo+vbit, zhi+vbit)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      return this_changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    // See if x+y can cause negative overflow into z-2**32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    if (long_ranges_overlap(xlo+ylo, xhi+yhi, zlo-vbit, zhi-vbit)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      return this_changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    // Now it's always safe to assume x+y does not overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    // This is true even if some pairs x,y might cause overflow, as long
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    // as that overflow value cannot fall into [zlo,zhi].
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    // Confident that the arithmetic is "as if infinite precision",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    // we can now use z's range to put constraints on those of x and y.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    // The "natural" range of x [xlo,xhi] can perhaps be narrowed to a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    // more "restricted" range by intersecting [xlo,xhi] with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    // range obtained by subtracting y's range from the asserted range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    // of the I2L conversion.  Here's the interval arithmetic algebra:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    //    x == z-y == [zlo,zhi]-[ylo,yhi] == [zlo,zhi]+[-yhi,-ylo]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    //    => x in [zlo-yhi, zhi-ylo]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    //    => x in [zlo-yhi, zhi-ylo] INTERSECT [xlo,xhi]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    //    => x in [xlo MAX zlo-yhi, xhi MIN zhi-ylo]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    jlong rxlo = MAX2(xlo, zlo - yhi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    jlong rxhi = MIN2(xhi, zhi - ylo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    // And similarly, x changing place with y:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    jlong rylo = MAX2(ylo, zlo - xhi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    jlong ryhi = MIN2(yhi, zhi - xlo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    if (rxlo > rxhi || rylo > ryhi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
      return this_changed;  // x or y is dying; don't mess w/ it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    if (op == Op_SubI) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      jlong rylo0 = rylo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
      rylo = -ryhi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
      ryhi = -rylo0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1006
    Node* cx = phase->transform( new (phase->C) ConvI2LNode(x, TypeLong::make(rxlo, rxhi, widen)) );
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1007
    Node* cy = phase->transform( new (phase->C) ConvI2LNode(y, TypeLong::make(rylo, ryhi, widen)) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    switch (op) {
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1009
    case Op_AddI:  return new (phase->C) AddLNode(cx, cy);
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1010
    case Op_SubI:  return new (phase->C) SubLNode(cx, cy);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    default:       ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
#endif //_LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  return this_changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
const Type *ConvL2DNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  const TypeLong *tl = t->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  if( tl->is_con() ) return TypeD::make( (double)tl->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
const Type *ConvL2FNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  const TypeLong *tl = t->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  if( tl->is_con() ) return TypeF::make( (float)tl->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
//----------------------------Identity-----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
Node *ConvL2INode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  // Convert L2I(I2L(x)) => x
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  if (in(1)->Opcode() == Op_ConvI2L)  return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
const Type *ConvL2INode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  const TypeLong *tl = t->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
  if (tl->is_con())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    // Easy case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    return TypeInt::make((jint)tl->get_con());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
// Return a node which is more "ideal" than the current node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
// Blow off prior masking to int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
Node *ConvL2INode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  Node *andl = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
  uint andl_op = andl->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  if( andl_op == Op_AndL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    // Blow off prior masking to int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    if( phase->type(andl->in(2)) == TypeLong::make( 0xFFFFFFFF ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
      set_req(1,andl->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  // Swap with a prior add: convL2I(addL(x,y)) ==> addI(convL2I(x),convL2I(y))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  // This replaces an 'AddL' with an 'AddI'.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  if( andl_op == Op_AddL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    // Don't do this for nodes which have more than one user since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
    // we'll end up computing the long add anyway.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    if (andl->outcnt() > 1) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    Node* x = andl->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    Node* y = andl->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    assert( x != andl && y != andl, "dead loop in ConvL2INode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    if (phase->type(x) == Type::TOP)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    if (phase->type(y) == Type::TOP)  return NULL;
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1084
    Node *add1 = phase->transform(new (phase->C) ConvL2INode(x));
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1085
    Node *add2 = phase->transform(new (phase->C) ConvL2INode(y));
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1086
    return new (phase->C) AddINode(add1,add2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
209
2a924148a40a 6667618: disable LoadL->ConvL2I ==> LoadI optimization
kvn
parents: 1
diff changeset
  1089
  // Disable optimization: LoadL->ConvL2I ==> LoadI.
2a924148a40a 6667618: disable LoadL->ConvL2I ==> LoadI optimization
kvn
parents: 1
diff changeset
  1090
  // It causes problems (sizes of Load and Store nodes do not match)
2a924148a40a 6667618: disable LoadL->ConvL2I ==> LoadI optimization
kvn
parents: 1
diff changeset
  1091
  // in objects initialization code and Escape Analysis.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
const Type *CastX2PNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  const Type* t = phase->type(in(1));
11959
0bf55e106849 7146442: assert(false) failed: bad AD file
kvn
parents: 10739
diff changeset
  1099
  if (t == Type::TOP) return Type::TOP;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  if (t->base() == Type_X && t->singleton()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
    uintptr_t bits = (uintptr_t) t->is_intptr_t()->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    if (bits == 0)   return TypePtr::NULL_PTR;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    return TypeRawPtr::make((address) bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
  return CastX2PNode::bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
static inline bool fits_in_int(const Type* t, bool but_not_min_int = false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
  if (t == Type::TOP)  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  const TypeX* tl = t->is_intptr_t();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  jint lo = min_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
  jint hi = max_jint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  if (but_not_min_int)  ++lo;  // caller wants to negate the value w/o overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
  return (tl->_lo >= lo) && (tl->_hi <= hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
static inline Node* addP_of_X2P(PhaseGVN *phase,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
                                Node* base,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
                                Node* dispX,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
                                bool negate = false) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  if (negate) {
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1123
    dispX = new (phase->C) SubXNode(phase->MakeConX(0), phase->transform(dispX));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  }
13895
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1125
  return new (phase->C) AddPNode(phase->C->top(),
f6dfe4123709 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 13886
diff changeset
  1126
                          phase->transform(new (phase->C) CastX2PNode(base)),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
                          phase->transform(dispX));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
Node *CastX2PNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  // convert CastX2P(AddX(x, y)) to AddP(CastX2P(x), y) if y fits in an int
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  int op = in(1)->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  Node* x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  Node* y;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  switch (op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  case Op_SubX:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    x = in(1)->in(1);
3914
bcfd1e08dcea 6883468: C2 compiler enters infinite loop in PhaseIterGVN::transform
kvn
parents: 3261
diff changeset
  1138
    // Avoid ideal transformations ping-pong between this and AddP for raw pointers.
bcfd1e08dcea 6883468: C2 compiler enters infinite loop in PhaseIterGVN::transform
kvn
parents: 3261
diff changeset
  1139
    if (phase->find_intptr_t_con(x, -1) == 0)
bcfd1e08dcea 6883468: C2 compiler enters infinite loop in PhaseIterGVN::transform
kvn
parents: 3261
diff changeset
  1140
      break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
    y = in(1)->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
    if (fits_in_int(phase->type(y), true)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      return addP_of_X2P(phase, x, y, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  case Op_AddX:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    x = in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    y = in(1)->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    if (fits_in_int(phase->type(y))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
      return addP_of_X2P(phase, x, y);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
    if (fits_in_int(phase->type(x))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      return addP_of_X2P(phase, y, x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
Node *CastX2PNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  if (in(1)->Opcode() == Op_CastP2X)  return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
const Type *CastP2XNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  const Type* t = phase->type(in(1));
11959
0bf55e106849 7146442: assert(false) failed: bad AD file
kvn
parents: 10739
diff changeset
  1170
  if (t == Type::TOP) return Type::TOP;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  if (t->base() == Type::RawPtr && t->singleton()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    uintptr_t bits = (uintptr_t) t->is_rawptr()->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    return TypeX::make(bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
  return CastP2XNode::bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
Node *CastP2XNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  return (in(0) && remove_dead_region(phase, can_reshape)) ? this : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
Node *CastP2XNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  if (in(1)->Opcode() == Op_CastX2P)  return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
// Remove redundant roundings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
Node *RoundFloatNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  // Do not round constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  if (phase->type(in(1))->base() == Type::FloatCon)  return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  int op = in(1)->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  // Redundant rounding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
  if( op == Op_RoundFloat ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  // Already rounded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
  if( op == Op_Parm ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
  if( op == Op_LoadF ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
const Type *RoundFloatNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
  return phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
// Remove redundant roundings.  Incoming arguments are already rounded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
Node *RoundDoubleNode::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  assert(Matcher::strict_fp_requires_explicit_rounding, "should only generate for Intel");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  // Do not round constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
  if (phase->type(in(1))->base() == Type::DoubleCon)  return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  int op = in(1)->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  // Redundant rounding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
  if( op == Op_RoundDouble ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
  // Already rounded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
  if( op == Op_Parm ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
  if( op == Op_LoadD ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  if( op == Op_ConvF2D ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  if( op == Op_ConvI2D ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
const Type *RoundDoubleNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  return phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
// Do not allow value-numbering
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
uint Opaque1Node::hash() const { return NO_HASH; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
uint Opaque1Node::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  return (&n == this);          // Always fail except on self
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
// If _major_progress, then more loop optimizations follow.  Do NOT remove
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
// the opaque Node until no more loop ops can happen.  Note the timing of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
// _major_progress; it's set in the major loop optimizations THEN comes the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
// call to IterGVN and any chance of hitting this code.  Hence there's no
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
// phase-ordering problem with stripping Opaque1 in IGVN followed by some
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
// more loop optimizations that require it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
Node *Opaque1Node::Identity( PhaseTransform *phase ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  return phase->C->major_progress() ? this : in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
// A node to prevent unwanted optimizations.  Allows constant folding.  Stops
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
// value-numbering, most Ideal calls or Identity functions.  This Node is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
// specifically designed to prevent the pre-increment value of a loop trip
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
// counter from being live out of the bottom of the loop (hence causing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
// pre- and post-increment values both being live and thus requiring an extra
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
// temp register and an extra move).  If we "accidentally" optimize through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
// this kind of a Node, we'll get slightly pessimal, but correct, code.  Thus
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
// it's OK to be slightly sloppy on optimizations here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
// Do not allow value-numbering
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
uint Opaque2Node::hash() const { return NO_HASH; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
uint Opaque2Node::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  return (&n == this);          // Always fail except on self
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
const Type *MoveL2DNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  const TypeLong *tl = t->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
  if( !tl->is_con() ) return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
  JavaValue v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  v.set_jlong(tl->get_con());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  return TypeD::make( v.get_jdouble() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
const Type *MoveI2FNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
  const TypeInt *ti = t->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  if( !ti->is_con() )   return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  JavaValue v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  v.set_jint(ti->get_con());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
  return TypeF::make( v.get_jfloat() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
const Type *MoveF2INode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  if( t == Type::TOP )       return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  if( t == Type::FLOAT ) return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  const TypeF *tf = t->is_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  JavaValue v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
  v.set_jfloat(tf->getf());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
  return TypeInt::make( v.get_jint() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
const Type *MoveD2LNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  const Type *t = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  if( t == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  if( t == Type::DOUBLE ) return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  const TypeD *td = t->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  JavaValue v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  v.set_jdouble(td->getd());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
  return TypeLong::make( v.get_jlong() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
}
2862
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1312
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1313
//------------------------------Value------------------------------------------
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1314
const Type* CountLeadingZerosINode::Value(PhaseTransform* phase) const {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1315
  const Type* t = phase->type(in(1));
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1316
  if (t == Type::TOP) return Type::TOP;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1317
  const TypeInt* ti = t->isa_int();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1318
  if (ti && ti->is_con()) {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1319
    jint i = ti->get_con();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1320
    // HD, Figure 5-6
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1321
    if (i == 0)
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1322
      return TypeInt::make(BitsPerInt);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1323
    int n = 1;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1324
    unsigned int x = i;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1325
    if (x >> 16 == 0) { n += 16; x <<= 16; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1326
    if (x >> 24 == 0) { n +=  8; x <<=  8; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1327
    if (x >> 28 == 0) { n +=  4; x <<=  4; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1328
    if (x >> 30 == 0) { n +=  2; x <<=  2; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1329
    n -= x >> 31;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1330
    return TypeInt::make(n);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1331
  }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1332
  return TypeInt::INT;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1333
}
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1334
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1335
//------------------------------Value------------------------------------------
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1336
const Type* CountLeadingZerosLNode::Value(PhaseTransform* phase) const {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1337
  const Type* t = phase->type(in(1));
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1338
  if (t == Type::TOP) return Type::TOP;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1339
  const TypeLong* tl = t->isa_long();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1340
  if (tl && tl->is_con()) {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1341
    jlong l = tl->get_con();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1342
    // HD, Figure 5-6
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1343
    if (l == 0)
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1344
      return TypeInt::make(BitsPerLong);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1345
    int n = 1;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1346
    unsigned int x = (((julong) l) >> 32);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1347
    if (x == 0) { n += 32; x = (int) l; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1348
    if (x >> 16 == 0) { n += 16; x <<= 16; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1349
    if (x >> 24 == 0) { n +=  8; x <<=  8; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1350
    if (x >> 28 == 0) { n +=  4; x <<=  4; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1351
    if (x >> 30 == 0) { n +=  2; x <<=  2; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1352
    n -= x >> 31;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1353
    return TypeInt::make(n);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1354
  }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1355
  return TypeInt::INT;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1356
}
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1357
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1358
//------------------------------Value------------------------------------------
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1359
const Type* CountTrailingZerosINode::Value(PhaseTransform* phase) const {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1360
  const Type* t = phase->type(in(1));
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1361
  if (t == Type::TOP) return Type::TOP;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1362
  const TypeInt* ti = t->isa_int();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1363
  if (ti && ti->is_con()) {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1364
    jint i = ti->get_con();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1365
    // HD, Figure 5-14
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1366
    int y;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1367
    if (i == 0)
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1368
      return TypeInt::make(BitsPerInt);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1369
    int n = 31;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1370
    y = i << 16; if (y != 0) { n = n - 16; i = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1371
    y = i <<  8; if (y != 0) { n = n -  8; i = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1372
    y = i <<  4; if (y != 0) { n = n -  4; i = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1373
    y = i <<  2; if (y != 0) { n = n -  2; i = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1374
    y = i <<  1; if (y != 0) { n = n -  1; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1375
    return TypeInt::make(n);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1376
  }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1377
  return TypeInt::INT;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1378
}
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1379
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1380
//------------------------------Value------------------------------------------
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1381
const Type* CountTrailingZerosLNode::Value(PhaseTransform* phase) const {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1382
  const Type* t = phase->type(in(1));
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1383
  if (t == Type::TOP) return Type::TOP;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1384
  const TypeLong* tl = t->isa_long();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1385
  if (tl && tl->is_con()) {
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1386
    jlong l = tl->get_con();
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1387
    // HD, Figure 5-14
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1388
    int x, y;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1389
    if (l == 0)
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1390
      return TypeInt::make(BitsPerLong);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1391
    int n = 63;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1392
    y = (int) l; if (y != 0) { n = n - 32; x = y; } else x = (((julong) l) >> 32);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1393
    y = x << 16; if (y != 0) { n = n - 16; x = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1394
    y = x <<  8; if (y != 0) { n = n -  8; x = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1395
    y = x <<  4; if (y != 0) { n = n -  4; x = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1396
    y = x <<  2; if (y != 0) { n = n -  2; x = y; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1397
    y = x <<  1; if (y != 0) { n = n -  1; }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1398
    return TypeInt::make(n);
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1399
  }
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1400
  return TypeInt::INT;
fad636edf18f 6823354: Add intrinsics for {Integer,Long}.{numberOfLeadingZeros,numberOfTrailingZeros}()
twisti
parents: 2745
diff changeset
  1401
}