hotspot/src/share/vm/opto/movenode.cpp
author zmajo
Tue, 30 Aug 2016 09:30:16 +0200
changeset 41052 3362c4368286
parent 35551 36ef3841fb34
permissions -rw-r--r--
8161720: Better byte behavior for off-heap data Summary: Normalize boolean values read with Unsafe. Reviewed-by: aph, simonis, jrose, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     1
/*
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     4
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     8
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    13
 * accompanied this code).
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    14
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    18
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    21
 * questions.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    22
 *
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    23
 */
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    24
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    25
#include "precompiled.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    26
#include "opto/addnode.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    27
#include "opto/connode.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    28
#include "opto/convertnode.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    29
#include "opto/movenode.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    30
#include "opto/phaseX.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    31
#include "opto/subnode.hpp"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    32
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    33
//=============================================================================
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    34
/*
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    35
 The major change is for CMoveP and StrComp.  They have related but slightly
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    36
 different problems.  They both take in TWO oops which are both null-checked
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    37
 independently before the using Node.  After CCP removes the CastPP's they need
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    38
 to pick up the guarding test edge - in this case TWO control edges.  I tried
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    39
 various solutions, all have problems:
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    40
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    41
 (1) Do nothing.  This leads to a bug where we hoist a Load from a CMoveP or a
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    42
 StrComp above a guarding null check.  I've seen both cases in normal -Xcomp
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    43
 testing.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    44
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    45
 (2) Plug the control edge from 1 of the 2 oops in.  Apparent problem here is
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    46
 to figure out which test post-dominates.  The real problem is that it doesn't
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    47
 matter which one you pick.  After you pick up, the dominating-test elider in
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    48
 IGVN can remove the test and allow you to hoist up to the dominating test on
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    49
 the chosen oop bypassing the test on the not-chosen oop.  Seen in testing.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    50
 Oops.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    51
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    52
 (3) Leave the CastPP's in.  This makes the graph more accurate in some sense;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    53
 we get to keep around the knowledge that an oop is not-null after some test.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    54
 Alas, the CastPP's interfere with GVN (some values are the regular oop, some
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    55
 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    56
 This cost us 10% on SpecJVM, even when I removed some of the more trivial
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    57
 cases in the optimizer.  Removing more useless Phi's started allowing Loads to
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    58
 illegally float above null checks.  I gave up on this approach.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    59
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    60
 (4) Add BOTH control edges to both tests.  Alas, too much code knows that
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    61
 control edges are in slot-zero ONLY.  Many quick asserts fail; no way to do
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    62
 this one.  Note that I really want to allow the CMoveP to float and add both
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    63
 control edges to the dependent Load op - meaning I can select early but I
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    64
 cannot Load until I pass both tests.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    65
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    66
 (5) Do not hoist CMoveP and StrComp.  To this end I added the v-call
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    67
 depends_only_on_test().  No obvious performance loss on Spec, but we are
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    68
 clearly conservative on CMoveP (also so on StrComp but that's unlikely to
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    69
 matter ever).
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    70
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    71
 */
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    72
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    73
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    74
//------------------------------Ideal------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    75
// Return a node which is more "ideal" than the current node.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    76
// Move constants to the right.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    77
Node *CMoveNode::Ideal(PhaseGVN *phase, bool can_reshape) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    78
  if( in(0) && remove_dead_region(phase, can_reshape) ) return this;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    79
  // Don't bother trying to transform a dead node
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    80
  if( in(0) && in(0)->is_top() )  return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    81
  assert( !phase->eqv(in(Condition), this) &&
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    82
         !phase->eqv(in(IfFalse), this) &&
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    83
         !phase->eqv(in(IfTrue), this), "dead loop in CMoveNode::Ideal" );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    84
  if( phase->type(in(Condition)) == Type::TOP )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    85
  return NULL; // return NULL when Condition is dead
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    86
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    87
  if( in(IfFalse)->is_Con() && !in(IfTrue)->is_Con() ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    88
    if( in(Condition)->is_Bool() ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    89
      BoolNode* b  = in(Condition)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    90
      BoolNode* b2 = b->negate(phase);
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
    91
      return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    92
    }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    93
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    94
  return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    95
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    96
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    97
//------------------------------is_cmove_id------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    98
// Helper function to check for CMOVE identity.  Shared with PhiNode::Identity
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
    99
Node *CMoveNode::is_cmove_id( PhaseTransform *phase, Node *cmp, Node *t, Node *f, BoolNode *b ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   100
  // Check for Cmp'ing and CMove'ing same values
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   101
  if( (phase->eqv(cmp->in(1),f) &&
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   102
       phase->eqv(cmp->in(2),t)) ||
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   103
     // Swapped Cmp is OK
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   104
     (phase->eqv(cmp->in(2),f) &&
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   105
      phase->eqv(cmp->in(1),t)) ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   106
       // Give up this identity check for floating points because it may choose incorrect
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   107
       // value around 0.0 and -0.0
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   108
       if ( cmp->Opcode()==Op_CmpF || cmp->Opcode()==Op_CmpD )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   109
       return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   110
       // Check for "(t==f)?t:f;" and replace with "f"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   111
       if( b->_test._test == BoolTest::eq )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   112
       return f;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   113
       // Allow the inverted case as well
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   114
       // Check for "(t!=f)?t:f;" and replace with "t"
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   115
       if( b->_test._test == BoolTest::ne )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   116
       return t;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   117
     }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   118
  return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   119
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   120
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   121
//------------------------------Identity---------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   122
// Conditional-move is an identity if both inputs are the same, or the test
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   123
// true or false.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   124
Node* CMoveNode::Identity(PhaseGVN* phase) {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   125
  if( phase->eqv(in(IfFalse),in(IfTrue)) ) // C-moving identical inputs?
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   126
  return in(IfFalse);         // Then it doesn't matter
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   127
  if( phase->type(in(Condition)) == TypeInt::ZERO )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   128
  return in(IfFalse);         // Always pick left(false) input
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   129
  if( phase->type(in(Condition)) == TypeInt::ONE )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   130
  return in(IfTrue);          // Always pick right(true) input
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   131
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   132
  // Check for CMove'ing a constant after comparing against the constant.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   133
  // Happens all the time now, since if we compare equality vs a constant in
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   134
  // the parser, we "know" the variable is constant on one path and we force
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   135
  // it.  Thus code like "if( x==0 ) {/*EMPTY*/}" ends up inserting a
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   136
  // conditional move: "x = (x==0)?0:x;".  Yucko.  This fix is slightly more
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   137
  // general in that we don't need constants.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   138
  if( in(Condition)->is_Bool() ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   139
    BoolNode *b = in(Condition)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   140
    Node *cmp = b->in(1);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   141
    if( cmp->is_Cmp() ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   142
      Node *id = is_cmove_id( phase, cmp, in(IfTrue), in(IfFalse), b );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   143
      if( id ) return id;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   144
    }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   145
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   146
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   147
  return this;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   148
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   149
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   150
//------------------------------Value------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   151
// Result is the meet of inputs
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   152
const Type* CMoveNode::Value(PhaseGVN* phase) const {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   153
  if( phase->type(in(Condition)) == Type::TOP )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   154
  return Type::TOP;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   155
  return phase->type(in(IfFalse))->meet_speculative(phase->type(in(IfTrue)));
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   156
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   157
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   158
//------------------------------make-------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   159
// Make a correctly-flavored CMove.  Since _type is directly determined
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   160
// from the inputs we do not need to specify it here.
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
   161
CMoveNode *CMoveNode::make(Node *c, Node *bol, Node *left, Node *right, const Type *t) {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   162
  switch( t->basic_type() ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   163
    case T_INT:     return new CMoveINode( bol, left, right, t->is_int() );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   164
    case T_FLOAT:   return new CMoveFNode( bol, left, right, t );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   165
    case T_DOUBLE:  return new CMoveDNode( bol, left, right, t );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   166
    case T_LONG:    return new CMoveLNode( bol, left, right, t->is_long() );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   167
    case T_OBJECT:  return new CMovePNode( c, bol, left, right, t->is_oopptr() );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   168
    case T_ADDRESS: return new CMovePNode( c, bol, left, right, t->is_ptr() );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   169
    case T_NARROWOOP: return new CMoveNNode( c, bol, left, right, t );
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   170
    default:
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   171
    ShouldNotReachHere();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   172
    return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   173
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   174
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   175
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   176
//=============================================================================
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   177
//------------------------------Ideal------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   178
// Return a node which is more "ideal" than the current node.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   179
// Check for conversions to boolean
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   180
Node *CMoveINode::Ideal(PhaseGVN *phase, bool can_reshape) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   181
  // Try generic ideal's first
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   182
  Node *x = CMoveNode::Ideal(phase, can_reshape);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   183
  if( x ) return x;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   184
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   185
  // If zero is on the left (false-case, no-move-case) it must mean another
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   186
  // constant is on the right (otherwise the shared CMove::Ideal code would
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   187
  // have moved the constant to the right).  This situation is bad for Intel
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   188
  // and a don't-care for Sparc.  It's bad for Intel because the zero has to
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   189
  // be manifested in a register with a XOR which kills flags, which are live
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   190
  // on input to the CMoveI, leading to a situation which causes excessive
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   191
  // spilling on Intel.  For Sparc, if the zero in on the left the Sparc will
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   192
  // zero a register via G0 and conditionally-move the other constant.  If the
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   193
  // zero is on the right, the Sparc will load the first constant with a
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   194
  // 13-bit set-lo and conditionally move G0.  See bug 4677505.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   195
  if( phase->type(in(IfFalse)) == TypeInt::ZERO && !(phase->type(in(IfTrue)) == TypeInt::ZERO) ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   196
    if( in(Condition)->is_Bool() ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   197
      BoolNode* b  = in(Condition)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   198
      BoolNode* b2 = b->negate(phase);
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
   199
      return make(in(Control), phase->transform(b2), in(IfTrue), in(IfFalse), _type);
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   200
    }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   201
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   202
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   203
  // Now check for booleans
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   204
  int flip = 0;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   205
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   206
  // Check for picking from zero/one
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   207
  if( phase->type(in(IfFalse)) == TypeInt::ZERO && phase->type(in(IfTrue)) == TypeInt::ONE ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   208
    flip = 1 - flip;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   209
  } else if( phase->type(in(IfFalse)) == TypeInt::ONE && phase->type(in(IfTrue)) == TypeInt::ZERO ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   210
  } else return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   211
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   212
  // Check for eq/ne test
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   213
  if( !in(1)->is_Bool() ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   214
  BoolNode *bol = in(1)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   215
  if( bol->_test._test == BoolTest::eq ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   216
  } else if( bol->_test._test == BoolTest::ne ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   217
    flip = 1-flip;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   218
  } else return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   219
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   220
  // Check for vs 0 or 1
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   221
  if( !bol->in(1)->is_Cmp() ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   222
  const CmpNode *cmp = bol->in(1)->as_Cmp();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   223
  if( phase->type(cmp->in(2)) == TypeInt::ZERO ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   224
  } else if( phase->type(cmp->in(2)) == TypeInt::ONE ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   225
    // Allow cmp-vs-1 if the other input is bounded by 0-1
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   226
    if( phase->type(cmp->in(1)) != TypeInt::BOOL )
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   227
    return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   228
    flip = 1 - flip;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   229
  } else return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   230
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   231
  // Convert to a bool (flipped)
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   232
  // Build int->bool conversion
34174
4db2fb26dc49 8140424: don't prefix developer and notproduct flag variables with CONST_ in product builds
twisti
parents: 32084
diff changeset
   233
  if (PrintOpto) { tty->print_cr("CMOV to I2B"); }
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   234
  Node *n = new Conv2BNode( cmp->in(1) );
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   235
  if( flip )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   236
  n = new XorINode( phase->transform(n), phase->intcon(1) );
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   237
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   238
  return n;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   239
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   240
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   241
//=============================================================================
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   242
//------------------------------Ideal------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   243
// Return a node which is more "ideal" than the current node.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   244
// Check for absolute value
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   245
Node *CMoveFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   246
  // Try generic ideal's first
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   247
  Node *x = CMoveNode::Ideal(phase, can_reshape);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   248
  if( x ) return x;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   249
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   250
  int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   251
  int  phi_x_idx = 0;           // Index of phi input where to find naked x
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   252
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   253
  // Find the Bool
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   254
  if( !in(1)->is_Bool() ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   255
  BoolNode *bol = in(1)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   256
  // Check bool sense
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   257
  switch( bol->_test._test ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   258
    case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   259
    case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   260
    case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   261
    case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   262
    default:           return NULL;                           break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   263
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   264
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   265
  // Find zero input of CmpF; the other input is being abs'd
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   266
  Node *cmpf = bol->in(1);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   267
  if( cmpf->Opcode() != Op_CmpF ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   268
  Node *X = NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   269
  bool flip = false;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   270
  if( phase->type(cmpf->in(cmp_zero_idx)) == TypeF::ZERO ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   271
    X = cmpf->in(3 - cmp_zero_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   272
  } else if (phase->type(cmpf->in(3 - cmp_zero_idx)) == TypeF::ZERO) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   273
    // The test is inverted, we should invert the result...
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   274
    X = cmpf->in(cmp_zero_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   275
    flip = true;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   276
  } else {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   277
    return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   278
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   279
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   280
  // If X is found on the appropriate phi input, find the subtract on the other
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   281
  if( X != in(phi_x_idx) ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   282
  int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   283
  Node *sub = in(phi_sub_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   284
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   285
  // Allow only SubF(0,X) and fail out for all others; NegF is not OK
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   286
  if( sub->Opcode() != Op_SubF ||
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   287
     sub->in(2) != X ||
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   288
     phase->type(sub->in(1)) != TypeF::ZERO ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   289
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   290
  Node *abs = new AbsFNode( X );
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   291
  if( flip )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   292
  abs = new SubFNode(sub->in(1), phase->transform(abs));
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   293
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   294
  return abs;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   295
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   296
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   297
//=============================================================================
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   298
//------------------------------Ideal------------------------------------------
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   299
// Return a node which is more "ideal" than the current node.
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   300
// Check for absolute value
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   301
Node *CMoveDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   302
  // Try generic ideal's first
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   303
  Node *x = CMoveNode::Ideal(phase, can_reshape);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   304
  if( x ) return x;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   305
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   306
  int  cmp_zero_idx = 0;        // Index of compare input where to look for zero
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   307
  int  phi_x_idx = 0;           // Index of phi input where to find naked x
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   308
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   309
  // Find the Bool
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   310
  if( !in(1)->is_Bool() ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   311
  BoolNode *bol = in(1)->as_Bool();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   312
  // Check bool sense
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   313
  switch( bol->_test._test ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   314
    case BoolTest::lt: cmp_zero_idx = 1; phi_x_idx = IfTrue;  break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   315
    case BoolTest::le: cmp_zero_idx = 2; phi_x_idx = IfFalse; break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   316
    case BoolTest::gt: cmp_zero_idx = 2; phi_x_idx = IfTrue;  break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   317
    case BoolTest::ge: cmp_zero_idx = 1; phi_x_idx = IfFalse; break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   318
    default:           return NULL;                           break;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   319
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   320
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   321
  // Find zero input of CmpD; the other input is being abs'd
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   322
  Node *cmpd = bol->in(1);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   323
  if( cmpd->Opcode() != Op_CmpD ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   324
  Node *X = NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   325
  bool flip = false;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   326
  if( phase->type(cmpd->in(cmp_zero_idx)) == TypeD::ZERO ) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   327
    X = cmpd->in(3 - cmp_zero_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   328
  } else if (phase->type(cmpd->in(3 - cmp_zero_idx)) == TypeD::ZERO) {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   329
    // The test is inverted, we should invert the result...
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   330
    X = cmpd->in(cmp_zero_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   331
    flip = true;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   332
  } else {
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   333
    return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   334
  }
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   335
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   336
  // If X is found on the appropriate phi input, find the subtract on the other
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   337
  if( X != in(phi_x_idx) ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   338
  int phi_sub_idx = phi_x_idx == IfTrue ? IfFalse : IfTrue;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   339
  Node *sub = in(phi_sub_idx);
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   340
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   341
  // Allow only SubD(0,X) and fail out for all others; NegD is not OK
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   342
  if( sub->Opcode() != Op_SubD ||
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   343
     sub->in(2) != X ||
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   344
     phase->type(sub->in(1)) != TypeD::ZERO ) return NULL;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   345
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   346
  Node *abs = new AbsDNode( X );
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   347
  if( flip )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23528
diff changeset
   348
  abs = new SubDNode(sub->in(1), phase->transform(abs));
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   349
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   350
  return abs;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   351
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   352
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   353
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   354
const Type* MoveL2DNode::Value(PhaseGVN* phase) const {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   355
  const Type *t = phase->type( in(1) );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   356
  if( t == Type::TOP ) return Type::TOP;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   357
  const TypeLong *tl = t->is_long();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   358
  if( !tl->is_con() ) return bottom_type();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   359
  JavaValue v;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   360
  v.set_jlong(tl->get_con());
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   361
  return TypeD::make( v.get_jdouble() );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   362
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   363
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   364
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   365
const Type* MoveI2FNode::Value(PhaseGVN* phase) const {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   366
  const Type *t = phase->type( in(1) );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   367
  if( t == Type::TOP ) return Type::TOP;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   368
  const TypeInt *ti = t->is_int();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   369
  if( !ti->is_con() )   return bottom_type();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   370
  JavaValue v;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   371
  v.set_jint(ti->get_con());
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   372
  return TypeF::make( v.get_jfloat() );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   373
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   374
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   375
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   376
const Type* MoveF2INode::Value(PhaseGVN* phase) const {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   377
  const Type *t = phase->type( in(1) );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   378
  if( t == Type::TOP )       return Type::TOP;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   379
  if( t == Type::FLOAT ) return TypeInt::INT;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   380
  const TypeF *tf = t->is_float_constant();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   381
  JavaValue v;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   382
  v.set_jfloat(tf->getf());
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   383
  return TypeInt::make( v.get_jint() );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   384
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   385
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   386
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 34174
diff changeset
   387
const Type* MoveD2LNode::Value(PhaseGVN* phase) const {
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   388
  const Type *t = phase->type( in(1) );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   389
  if( t == Type::TOP ) return Type::TOP;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   390
  if( t == Type::DOUBLE ) return TypeLong::LONG;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   391
  const TypeD *td = t->is_double_constant();
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   392
  JavaValue v;
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   393
  v.set_jdouble(td->getd());
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   394
  return TypeLong::make( v.get_jlong() );
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   395
}
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents:
diff changeset
   396
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   397
#ifndef PRODUCT
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   398
//----------------------------BinaryNode---------------------------------------
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   399
// The set of related nodes for a BinaryNode is all data inputs and all outputs
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   400
// till level 2 (i.e., one beyond the associated CMoveNode). In compact mode,
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   401
// it's the inputs till level 1 and the outputs till level 2.
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   402
void BinaryNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   403
  if (compact) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   404
    this->collect_nodes(in_rel, 1, false, true);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   405
  } else {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   406
    this->collect_nodes_in_all_data(in_rel, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   407
  }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   408
  this->collect_nodes(out_rel, -2, false, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   409
}
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 25930
diff changeset
   410
#endif