src/hotspot/share/opto/mulnode.cpp
author coleenp
Tue, 31 Oct 2017 11:55:09 -0400
changeset 47765 b7c7428eaab9
parent 47216 71c04702a3d5
child 51050 96ea37459ca7
permissions -rw-r--r--
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot Summary: Removed hotspot version of jvm*h and jni*h files. Reviewed-by: ihse, mchung, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46325
diff changeset
     2
 * Copyright (c) 1997, 2017, 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: 3597
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3597
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: 3597
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/addnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/connode.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 22845
diff changeset
    29
#include "opto/convertnode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/memnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/mulnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "opto/subnode.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
// Portions of code courtesy of Clifford Click
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//------------------------------hash-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// Hash function over MulNodes.  Needs to be commutative; i.e., I swap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// (commute) inputs to MulNodes willy-nilly so the hash function must return
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// the same value in the presence of edge swapping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
uint MulNode::hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Multiplying a one preserves the other argument
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
    49
Node* MulNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  register const Type *one = mul_id();  // The multiplicative identity
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if( phase->type( in(1) )->higher_equal( one ) ) return in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if( phase->type( in(2) )->higher_equal( one ) ) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// We also canonicalize the Node, moving constants to the right input,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// and flatten expressions (so that 1+x+2 becomes x+3).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
Node *MulNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  Node *progress = NULL;        // Progress flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // We are OK if right is a constant, or right is a load and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // left is a non-constant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if( !(t2->singleton() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        (in(2)->is_Load() && !(t1->singleton() || in(1)->is_Load())) ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    if( t1->singleton() ||       // Left input is a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        // Otherwise, sort inputs (commutativity) to help value numbering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        (in(1)->_idx > in(2)->_idx) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      const Type *t = t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      t1 = t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      t2 = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      progress = this;            // Made progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // If the right input is a constant, and the left input is a product of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // constant, flatten the expression tree.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  uint op = Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if( t2->singleton() &&        // Right input is a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      op != Op_MulF &&          // Float & double cannot reassociate
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      op != Op_MulD ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if( t2 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    Node *mul1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    int   op1 = mul1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    if( phase->eqv( mul1, this ) || phase->eqv( in(2), this ) ||
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46325
diff changeset
    91
        ( ( op1 == mul_opcode() || op1 == add_opcode() ) &&
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46325
diff changeset
    92
          ( phase->eqv( mul1->in(1), this ) || phase->eqv( mul1->in(2), this ) ||
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46325
diff changeset
    93
            phase->eqv( mul1->in(1), mul1 ) || phase->eqv( mul1->in(2), mul1 ) ) ) )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      assert(false, "dead loop in MulNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if( mul1->Opcode() == mul_opcode() ) {  // Left input is a multiply?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      // Mul of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      const Type *t12 = phase->type( mul1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      if( t12->singleton() && t12 != Type::TOP) { // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        // Compute new constant; check for overflow
10255
bab46e6f7661 7069452: Cleanup NodeFlags
kvn
parents: 7397
diff changeset
   102
        const Type *tcon01 = ((MulNode*)mul1)->mul_ring(t2,t12);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        if( tcon01->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
          // The Mul of the flattened expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
          set_req(1, mul1->in(1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
          set_req(2, phase->makecon( tcon01 ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
          t2 = tcon01;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
          progress = this;      // Made progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // If the right input is a constant, and the left input is an add of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // constant, flatten the tree: (X+con1)*con0 ==> X*con0 + con1*con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    const Node *add1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if( add1->Opcode() == add_opcode() ) {      // Left input is an add?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      // Add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      const Type *t12 = phase->type( add1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        assert( add1->in(1) != add1, "dead loop in MulNode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        // Compute new constant; check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        const Type *tcon01 = mul_ring(t2,t12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        if( tcon01->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
        // Convert (X+con1)*con0 into X*con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
          Node *mul = clone();    // mul = ()*con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
          mul->set_req(1,add1->in(1));  // mul = X*con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
          mul = phase->transform(mul);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          Node *add2 = add1->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
          add2->set_req(1, mul);        // X*con0 + con0*con1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
          add2->set_req(2, phase->makecon(tcon01) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
          progress = add2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    } // End of is left input an add
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  } // End of is right input a Mul
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return progress;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
//------------------------------Value-----------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   142
const Type* MulNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // Either input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  int op = Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    const Type *zero = add_id();        // The multiplicative zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    if( t1->higher_equal( zero ) ) return zero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if( t2->higher_equal( zero ) ) return zero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
1436
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   162
#if defined(IA32)
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   163
  // Can't trust native compilers to properly fold strict double
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   164
  // multiplication with round-to-zero on this platform.
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   165
  if (op == Op_MulD && phase->C->method()->is_strict()) {
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   166
    return TypeD::DOUBLE;
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   167
  }
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   168
#endif
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   169
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return mul_ring(t1,t2);            // Local flavor of type multiplication
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // Swap constant to right
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  jint con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if ((con = in(1)->find_int_con(0)) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    // Finish rest of method to use info in 'con'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  } else if ((con = in(2)->find_int_con(0)) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // Now we have a constant Node on the right and the constant in con
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  if( con == 0 ) return NULL;   // By zero is handled by Value call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  if( con == 1 ) return NULL;   // By one  is handled by Identity call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // Check for negative constant; if so negate the final result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  bool sign_flip = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if( con < 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    con = -con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    sign_flip = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Get low bit; check for being the only bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  Node *res = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  jint bit1 = con & -con;       // Extract low bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if( bit1 == con ) {           // Found a power of 2?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   202
    res = new LShiftINode( in(1), phase->intcon(log2_intptr(bit1)) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // Check for constant with 2 bits set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    jint bit2 = con-bit1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    bit2 = bit2 & -bit2;          // Extract 2nd bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    if( bit2 + bit1 == con ) {    // Found all bits in con?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   209
      Node *n1 = phase->transform( new LShiftINode( in(1), phase->intcon(log2_intptr(bit1)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   210
      Node *n2 = phase->transform( new LShiftINode( in(1), phase->intcon(log2_intptr(bit2)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   211
      res = new AddINode( n2, n1 );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    } else if (is_power_of_2(con+1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      // Sleezy: power-of-2 -1.  Next time be generic.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      jint temp = (jint) (con + 1);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   216
      Node *n1 = phase->transform( new LShiftINode( in(1), phase->intcon(log2_intptr(temp)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   217
      res = new SubINode( n1, in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  if( sign_flip ) {             // Need to negate result?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    res = phase->transform(res);// Transform, before making the zero con
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   225
    res = new SubINode(phase->intcon(0),res);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  return res;                   // Return final result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// Compute the product type of two integer ranges into this node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Fetch endpoints of all ranges
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   238
  jint lo0 = r0->_lo;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  double a = (double)lo0;
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   240
  jint hi0 = r0->_hi;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  double b = (double)hi0;
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   242
  jint lo1 = r1->_lo;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  double c = (double)lo1;
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
   244
  jint hi1 = r1->_hi;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  double d = (double)hi1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Compute all endpoints & check for overflow
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   248
  int32_t A = java_multiply(lo0, lo1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if( (double)A != a*c ) return TypeInt::INT; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   250
  int32_t B = java_multiply(lo0, hi1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if( (double)B != a*d ) return TypeInt::INT; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   252
  int32_t C = java_multiply(hi0, lo1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if( (double)C != b*c ) return TypeInt::INT; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   254
  int32_t D = java_multiply(hi0, hi1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  if( (double)D != b*d ) return TypeInt::INT; // Overflow?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  else { lo0 = B; hi0 = A; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if( C < D ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    if( C < lo0 ) lo0 = C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    if( D > hi0 ) hi0 = D;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    if( D < lo0 ) lo0 = D;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    if( C > hi0 ) hi0 = C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  return TypeInt::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // Swap constant to right
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  jlong con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  if ((con = in(1)->find_long_con(0)) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    // Finish rest of method to use info in 'con'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  } else if ((con = in(2)->find_long_con(0)) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // Now we have a constant Node on the right and the constant in con
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  if( con == CONST64(0) ) return NULL;  // By zero is handled by Value call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if( con == CONST64(1) ) return NULL;  // By one  is handled by Identity call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // Check for negative constant; if so negate the final result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  bool sign_flip = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if( con < 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    con = -con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    sign_flip = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // Get low bit; check for being the only bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  Node *res = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  jlong bit1 = con & -con;      // Extract low bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  if( bit1 == con ) {           // Found a power of 2?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   298
    res = new LShiftLNode( in(1), phase->intcon(log2_long(bit1)) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    // Check for constant with 2 bits set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    jlong bit2 = con-bit1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    bit2 = bit2 & -bit2;          // Extract 2nd bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    if( bit2 + bit1 == con ) {    // Found all bits in con?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   305
      Node *n1 = phase->transform( new LShiftLNode( in(1), phase->intcon(log2_long(bit1)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   306
      Node *n2 = phase->transform( new LShiftLNode( in(1), phase->intcon(log2_long(bit2)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   307
      res = new AddLNode( n2, n1 );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    } else if (is_power_of_2_long(con+1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      // Sleezy: power-of-2 -1.  Next time be generic.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      jlong temp = (jlong) (con + 1);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   312
      Node *n1 = phase->transform( new LShiftLNode( in(1), phase->intcon(log2_long(temp)) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   313
      res = new SubLNode( n1, in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  if( sign_flip ) {             // Need to negate result?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    res = phase->transform(res);// Transform, before making the zero con
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   321
    res = new SubLNode(phase->longcon(0),res);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  return res;                   // Return final result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// Compute the product type of two integer ranges into this node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  const TypeLong *r0 = t0->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  const TypeLong *r1 = t1->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // Fetch endpoints of all ranges
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  jlong lo0 = r0->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  double a = (double)lo0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  jlong hi0 = r0->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  double b = (double)hi0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  jlong lo1 = r1->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  double c = (double)lo1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  jlong hi1 = r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  double d = (double)hi1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // Compute all endpoints & check for overflow
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   344
  jlong A = java_multiply(lo0, lo1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if( (double)A != a*c ) return TypeLong::LONG; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   346
  jlong B = java_multiply(lo0, hi1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  if( (double)B != a*d ) return TypeLong::LONG; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   348
  jlong C = java_multiply(hi0, lo1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  if( (double)C != b*c ) return TypeLong::LONG; // Overflow?
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   350
  jlong D = java_multiply(hi0, hi1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  if( (double)D != b*d ) return TypeLong::LONG; // Overflow?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  else { lo0 = B; hi0 = A; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  if( C < D ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    if( C < lo0 ) lo0 = C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if( D > hi0 ) hi0 = D;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    if( D < lo0 ) lo0 = D;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    if( C > hi0 ) hi0 = C;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  return TypeLong::make(lo0, hi0, MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// Compute the product type of two double ranges into this node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
const Type *MulFNode::mul_ring(const Type *t0, const Type *t1) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  if( t0 == Type::FLOAT || t1 == Type::FLOAT ) return Type::FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  return TypeF::make( t0->getf() * t1->getf() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// Compute the product type of two double ranges into this node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
const Type *MulDNode::mul_ring(const Type *t0, const Type *t1) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  if( t0 == Type::DOUBLE || t1 == Type::DOUBLE ) return Type::DOUBLE;
1436
6869d58f4f58 6717150: improper constant folding of subnormal strictfp multiplications and divides
rasbold
parents: 670
diff changeset
   378
  // We must be multiplying 2 double constants.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  return TypeD::make( t0->getd() * t1->getd() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
//=============================================================================
392
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   383
//------------------------------Value------------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   384
const Type* MulHiLNode::Value(PhaseGVN* phase) const {
392
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   385
  // Either input is TOP ==> the result is TOP
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   386
  const Type *t1 = phase->type( in(1) );
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   387
  const Type *t2 = phase->type( in(2) );
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   388
  if( t1 == Type::TOP ) return Type::TOP;
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   389
  if( t2 == Type::TOP ) return Type::TOP;
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   390
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   391
  // Either input is BOTTOM ==> the result is the local BOTTOM
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   392
  const Type *bot = bottom_type();
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   393
  if( (t1 == bot) || (t2 == bot) ||
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   394
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   395
    return bot;
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   396
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   397
  // It is not worth trying to constant fold this stuff!
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   398
  return TypeLong::LONG;
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   399
}
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   400
0b3167e2f2de 6603011: RFE: Optimize long division
rasbold
parents: 1
diff changeset
   401
//=============================================================================
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
// Supplied function returns the product of the inputs IN THE CURRENT RING.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
// For the logical operations the ring's MUL is really a logical AND function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
const Type *AndINode::mul_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  const TypeInt *r0 = t0->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  const TypeInt *r1 = t1->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  int widen = MAX2(r0->_widen,r1->_widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // If either input is a constant, might be able to trim cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  if( !r0->is_con() && !r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    return TypeInt::INT;        // No constants to be had
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  // Both constants?  Return bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if( r0->is_con() && r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    return TypeInt::make( r0->get_con() & r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  if( r0->is_con() && r0->get_con() > 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    return TypeInt::make(0, r0->get_con(), widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  if( r1->is_con() && r1->get_con() > 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    return TypeInt::make(0, r1->get_con(), widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  if( r0 == TypeInt::BOOL || r1 == TypeInt::BOOL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  return TypeInt::INT;          // No constants to be had
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// Masking off the high bits of an unsigned load is not required
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   435
Node* AndINode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  // x & x => x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  if (phase->eqv(in(1), in(2))) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   440
  Node* in1 = in(1);
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   441
  uint op = in1->Opcode();
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   442
  const TypeInt* t2 = phase->type(in(2))->isa_int();
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   443
  if (t2 && t2->is_con()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    int con = t2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    // Masking off high bits which are always zero is useless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    const TypeInt* t1 = phase->type( in(1) )->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    if (t1 != NULL && t1->_lo >= 0) {
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   448
      jint t1_support = right_n_bits(1 + log2_intptr(t1->_hi));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      if ((t1_support & con) == t1_support)
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   450
        return in1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // Masking off the high bits of a unsigned-shift-right is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    // needed either.
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   454
    if (op == Op_URShiftI) {
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   455
      const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   456
      if (t12 && t12->is_con()) {  // Shift is by a constant
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   457
        int shift = t12->get_con();
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   458
        shift &= BitsPerJavaInteger - 1;  // semantics of Java shifts
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   459
        int mask = max_juint >> shift;
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   460
        if ((mask & con) == mask)  // If AND is useless, skip it
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   461
          return in1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  return MulNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
Node *AndINode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Special case constant AND mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  const TypeInt *t2 = phase->type( in(2) )->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  const int mask = t2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  Node *load = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  uint lop = load->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  // Masking bits off of a Character?  Hi bits are already zero.
2022
28ce8115a91d 6796746: rename LoadC (char) opcode class to LoadUS (unsigned short)
twisti
parents: 1436
diff changeset
   478
  if( lop == Op_LoadUS &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
      (mask & 0xFFFF0000) )     // Can we make a smaller mask?
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   480
    return new AndINode(load,phase->intcon(mask&0xFFFF));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  // Masking bits off of a Short?  Loading a Character does some masking
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   483
  if (can_reshape &&
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   484
      load->outcnt() == 1 && load->unique_out() == this) {
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   485
    if (lop == Op_LoadS && (mask & 0xFFFF0000) == 0 ) {
36830
ebc8b5e23f63 8152773: C2: LoadNode properties aren't preserved when converting between signed/unsigned variants
vlivanov
parents: 35551
diff changeset
   486
      Node* ldus = load->as_Load()->convert_to_unsigned_load(*phase);
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   487
      ldus = phase->transform(ldus);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   488
      return new AndINode(ldus, phase->intcon(mask & 0xFFFF));
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   489
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   491
    // Masking sign bits off of a Byte?  Do an unsigned byte load plus
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   492
    // an and.
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   493
    if (lop == Op_LoadB && (mask & 0xFFFFFF00) == 0) {
36830
ebc8b5e23f63 8152773: C2: LoadNode properties aren't preserved when converting between signed/unsigned variants
vlivanov
parents: 35551
diff changeset
   494
      Node* ldub = load->as_Load()->convert_to_unsigned_load(*phase);
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   495
      ldub = phase->transform(ldub);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   496
      return new AndINode(ldub, phase->intcon(mask));
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   497
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  // Masking off sign bits?  Dont make them!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  if( lop == Op_RShiftI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    const TypeInt *t12 = phase->type(load->in(2))->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    if( t12 && t12->is_con() ) { // Shift is by a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
      int shift = t12->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
      shift &= BitsPerJavaInteger-1;  // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      const int sign_bits_mask = ~right_n_bits(BitsPerJavaInteger - shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      // If the AND'ing of the 2 masks has no bits, then only original shifted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      // bits survive.  NO sign-extension bits survive the maskings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
      if( (sign_bits_mask & mask) == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
        // Use zero-fill shift instead
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   511
        Node *zshift = phase->transform(new URShiftINode(load->in(1),load->in(2)));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   512
        return new AndINode( zshift, in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // Check for 'negate/and-1', a pattern emitted when someone asks for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  // 'mod 2'.  Negate leaves the low order bit unchanged (think: complement
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  // plus 1) and the mask is of the low order bit.  Skip the negate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  if( lop == Op_SubI && mask == 1 && load->in(1) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      phase->type(load->in(1)) == TypeInt::ZERO )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   522
    return new AndINode( load->in(2), in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
//------------------------------mul_ring---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
// Supplied function returns the product of the inputs IN THE CURRENT RING.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
// For the logical operations the ring's MUL is really a logical AND function.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
// This also type-checks the inputs for sanity.  Guaranteed never to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
// be passed a TOP or BOTTOM type, these are filtered out by pre-check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
const Type *AndLNode::mul_ring( const Type *t0, const Type *t1 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  const TypeLong *r0 = t0->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  const TypeLong *r1 = t1->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  int widen = MAX2(r0->_widen,r1->_widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  // If either input is a constant, might be able to trim cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  if( !r0->is_con() && !r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    return TypeLong::LONG;      // No constants to be had
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  // Both constants?  Return bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  if( r0->is_con() && r1->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    return TypeLong::make( r0->get_con() & r1->get_con() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  if( r0->is_con() && r0->get_con() > 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    return TypeLong::make(CONST64(0), r0->get_con(), widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  if( r1->is_con() && r1->get_con() > 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    return TypeLong::make(CONST64(0), r1->get_con(), widen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  return TypeLong::LONG;        // No constants to be had
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
// Masking off the high bits of an unsigned load is not required
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   557
Node* AndLNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  // x & x => x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  if (phase->eqv(in(1), in(2))) return in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  Node *usr = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  const TypeLong *t2 = phase->type( in(2) )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  if( t2 && t2->is_con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    jlong con = t2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    // Masking off high bits which are always zero is useless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    const TypeLong* t1 = phase->type( in(1) )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    if (t1 != NULL && t1->_lo >= 0) {
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   569
      int bit_count = log2_long(t1->_hi) + 1;
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   570
      jlong t1_support = jlong(max_julong >> (BitsPerJavaLong - bit_count));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      if ((t1_support & con) == t1_support)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
        return usr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    uint lop = usr->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    // Masking off the high bits of a unsigned-shift-right is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    // needed either.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    if( lop == Op_URShiftL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
      const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   579
      if( t12 && t12->is_con() ) {  // Shift is by a constant
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   580
        int shift = t12->get_con();
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   581
        shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   582
        jlong mask = max_julong >> shift;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
        if( (mask&con) == mask )  // If AND is useless, skip it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
          return usr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  return MulNode::Identity(phase);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  // Special case constant AND mask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  const TypeLong *t2 = phase->type( in(2) )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  const jlong mask = t2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
2150
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2023
diff changeset
   598
  Node* in1 = in(1);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2023
diff changeset
   599
  uint op = in1->Opcode();
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2023
diff changeset
   600
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   601
  // Are we masking a long that was converted from an int with a mask
3597
572bbef24585 6863155: Server compiler generates incorrect code (x86, long, bitshift, bitmask)
twisti
parents: 3177
diff changeset
   602
  // that fits in 32-bits?  Commute them and use an AndINode.  Don't
572bbef24585 6863155: Server compiler generates incorrect code (x86, long, bitshift, bitmask)
twisti
parents: 3177
diff changeset
   603
  // convert masks which would cause a sign extension of the integer
572bbef24585 6863155: Server compiler generates incorrect code (x86, long, bitshift, bitmask)
twisti
parents: 3177
diff changeset
   604
  // value.  This check includes UI2L masks (0x00000000FFFFFFFF) which
572bbef24585 6863155: Server compiler generates incorrect code (x86, long, bitshift, bitmask)
twisti
parents: 3177
diff changeset
   605
  // would be optimized away later in Identity.
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 24923
diff changeset
   606
  if (op == Op_ConvI2L && (mask & UCONST64(0xFFFFFFFF80000000)) == 0) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   607
    Node* andi = new AndINode(in1->in(1), phase->intcon(mask));
3597
572bbef24585 6863155: Server compiler generates incorrect code (x86, long, bitshift, bitmask)
twisti
parents: 3177
diff changeset
   608
    andi = phase->transform(andi);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   609
    return new ConvI2LNode(andi);
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   610
  }
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   611
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // Masking off sign bits?  Dont make them!
2150
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2023
diff changeset
   613
  if (op == Op_RShiftL) {
3177
f467776fc753 5057225: Remove useless I2L conversions
twisti
parents: 2150
diff changeset
   614
    const TypeInt* t12 = phase->type(in1->in(2))->isa_int();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    if( t12 && t12->is_con() ) { // Shift is by a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
      int shift = t12->get_con();
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   617
      shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   618
      const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - shift)) -1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
      // If the AND'ing of the 2 masks has no bits, then only original shifted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      // bits survive.  NO sign-extension bits survive the maskings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      if( (sign_bits_mask & mask) == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
        // Use zero-fill shift instead
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   623
        Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2)));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   624
        return new AndLNode(zshift, in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  return MulNode::Ideal(phase, can_reshape);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
//=============================================================================
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   633
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   634
static int getShiftCon(PhaseGVN *phase, Node *shiftNode, int retVal) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   635
  const Type *t = phase->type(shiftNode->in(2));
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   636
  if (t == Type::TOP) return retVal;       // Right input is dead.
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   637
  const TypeInt *t2 = t->isa_int();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   638
  if (!t2 || !t2->is_con()) return retVal; // Right input is a constant.
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   639
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   640
  return t2->get_con();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   641
}
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   642
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   643
static int maskShiftAmount(PhaseGVN *phase, Node *shiftNode, int nBits) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   644
  int       shift = getShiftCon(phase, shiftNode, 0);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   645
  int maskedShift = shift & (nBits - 1);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   646
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   647
  if (maskedShift == 0) return 0;         // Let Identity() handle 0 shift count.
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   648
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   649
  if (shift != maskedShift) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   650
    shiftNode->set_req(2, phase->intcon(maskedShift)); // Replace shift count with masked value.
46325
0fa9327949f8 8176441: assert(false) failed: modified node was not processed by IGVN.transform_old()
thartmann
parents: 46277
diff changeset
   651
    phase->igvn_rehash_node_delayed(shiftNode);
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   652
  }
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   653
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   654
  return maskedShift;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   655
}
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   656
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   658
Node* LShiftINode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   659
  return ((getShiftCon(phase, this, -1) & (BitsPerJavaInteger - 1)) == 0) ? in(1) : this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
// If the right input is a constant, and the left input is an add of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
// constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
Node *LShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   666
  int con = maskShiftAmount(phase, this, BitsPerJavaInteger);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   667
  if (con == 0) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   668
    return NULL;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   669
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  Node *add1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  int add1_op = add1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  if( add1_op == Op_AddI ) {    // Left input is an add?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    assert( add1 != add1->in(1), "dead loop in LShiftINode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    const TypeInt *t12 = phase->type(add1->in(2))->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    if( t12 && t12->is_con() ){ // Left input is an add of a con?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
      // Transform is legal, but check for profit.  Avoid breaking 'i2s'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      // and 'i2b' patterns which typically fold into 'StoreC/StoreB'.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      if( con < 16 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
        // Compute X << con0
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   682
        Node *lsh = phase->transform( new LShiftINode( add1->in(1), in(2) ) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        // Compute X<<con0 + (con1<<con0)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   684
        return new AddINode( lsh, phase->intcon(t12->get_con() << con));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  // Check for "(x>>c0)<<c0" which just masks off low bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  if( (add1_op == Op_RShiftI || add1_op == Op_URShiftI ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      add1->in(2) == in(2) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    // Convert to "(x & -(1<<c0))"
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   693
    return new AndINode(add1->in(1),phase->intcon( -(1<<con)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  if( add1_op == Op_AndI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    Node *add2 = add1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    int add2_op = add2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
    if( (add2_op == Op_RShiftI || add2_op == Op_URShiftI ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        add2->in(2) == in(2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      // Convert to "(x & (Y<<c0))"
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   702
      Node *y_sh = phase->transform( new LShiftINode( add1->in(2), in(2) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   703
      return new AndINode( add2->in(1), y_sh );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  // Check for ((x & ((1<<(32-c0))-1)) << c0) which ANDs off high bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  // before shifting them away.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  const jint bits_mask = right_n_bits(BitsPerJavaInteger-con);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  if( add1_op == Op_AndI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      phase->type(add1->in(2)) == TypeInt::make( bits_mask ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   712
    return new LShiftINode( add1->in(1), in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
// A LShiftINode shifts its input2 left by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   719
const Type* LShiftINode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  if( t1 == TypeInt::ZERO ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  if( (t1 == TypeInt::INT) || (t2 == TypeInt::INT) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  const TypeInt *r1 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  const TypeInt *r2 = t2->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  if (!r2->is_con())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  uint shift = r2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  shift &= BitsPerJavaInteger-1;  // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  // Shift by a multiple of 32 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  // If the shift is a constant, shift the bounds of the type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  // unless this could lead to an overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  if (!r1->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    jint lo = r1->_lo, hi = r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
    if (((lo << shift) >> shift) == lo &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        ((hi << shift) >> shift) == hi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      // No overflow.  The range shifts up cleanly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      return TypeInt::make((jint)lo << (jint)shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
                           (jint)hi << (jint)shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
                           MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  return TypeInt::make( (jint)r1->get_con() << (jint)shift );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   766
Node* LShiftLNode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   767
  return ((getShiftCon(phase, this, -1) & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
// If the right input is a constant, and the left input is an add of a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
// constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
Node *LShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   774
  int con = maskShiftAmount(phase, this, BitsPerJavaLong);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   775
  if (con == 0) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   776
    return NULL;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   777
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // Left input is an add of a constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  Node *add1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  int add1_op = add1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  if( add1_op == Op_AddL ) {    // Left input is an add?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    // Avoid dead data cycles from dead loops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    assert( add1 != add1->in(1), "dead loop in LShiftLNode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    const TypeLong *t12 = phase->type(add1->in(2))->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    if( t12 && t12->is_con() ){ // Left input is an add of a con?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      // Compute X << con0
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   788
      Node *lsh = phase->transform( new LShiftLNode( add1->in(1), in(2) ) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      // Compute X<<con0 + (con1<<con0)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   790
      return new AddLNode( lsh, phase->longcon(t12->get_con() << con));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  // Check for "(x>>c0)<<c0" which just masks off low bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  if( (add1_op == Op_RShiftL || add1_op == Op_URShiftL ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      add1->in(2) == in(2) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    // Convert to "(x & -(1<<c0))"
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   798
    return new AndLNode(add1->in(1),phase->longcon( -(CONST64(1)<<con)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  if( add1_op == Op_AndL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    Node *add2 = add1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    int add2_op = add2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    if( (add2_op == Op_RShiftL || add2_op == Op_URShiftL ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
        add2->in(2) == in(2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
      // Convert to "(x & (Y<<c0))"
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   807
      Node *y_sh = phase->transform( new LShiftLNode( add1->in(2), in(2) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   808
      return new AndLNode( add2->in(1), y_sh );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  // before shifting them away.
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
   814
  const jlong bits_mask = jlong(max_julong >> con);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  if( add1_op == Op_AndL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      phase->type(add1->in(2)) == TypeLong::make( bits_mask ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   817
    return new LShiftLNode( add1->in(1), in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
// A LShiftLNode shifts its input2 left by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   824
const Type* LShiftLNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  if( (t1 == TypeLong::LONG) || (t2 == TypeInt::INT) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
  const TypeLong *r1 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  const TypeInt  *r2 = t2->is_int();  // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  if (!r2->is_con())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  uint shift = r2->get_con();
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
   848
  shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  // Shift by a multiple of 64 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  // If the shift is a constant, shift the bounds of the type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  // unless this could lead to an overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  if (!r1->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    jlong lo = r1->_lo, hi = r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    if (((lo << shift) >> shift) == lo &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
        ((hi << shift) >> shift) == hi) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      // No overflow.  The range shifts up cleanly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
      return TypeLong::make((jlong)lo << (jint)shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
                            (jlong)hi << (jint)shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
                            MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  return TypeLong::make( (jlong)r1->get_con() << (jint)shift );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   871
Node* RShiftINode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   872
  int shift = getShiftCon(phase, this, -1);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   873
  if (shift == -1) return this;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   874
  if ((shift & (BitsPerJavaInteger - 1)) == 0) return in(1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  // Check for useless sign-masking
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   877
  if (in(1)->Opcode() == Op_LShiftI &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
      in(1)->req() == 3 &&
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   879
      in(1)->in(2) == in(2)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    shift &= BitsPerJavaInteger-1; // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    // Compute masks for which this shifting doesn't change
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   882
    int lo = (-1 << (BitsPerJavaInteger - ((uint)shift)-1)); // FFFF8000
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    int hi = ~lo;               // 00007FFF
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    const TypeInt *t11 = phase->type(in(1)->in(1))->isa_int();
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   885
    if (!t11) return this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    // Does actual value fit inside of mask?
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   887
    if (lo <= t11->_lo && t11->_hi <= hi) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
      return in(1)->in(1);      // Then shifting is a nop
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   889
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
Node *RShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  // Inputs may be TOP if they are dead.
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   898
  const TypeInt *t1 = phase->type(in(1))->isa_int();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   899
  if (!t1) return NULL;        // Left input is an integer
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  const TypeInt *t3;  // type of in(1).in(2)
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   901
  int shift = maskShiftAmount(phase, this, BitsPerJavaInteger);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   902
  if (shift == 0) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   903
    return NULL;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
   904
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  // Check for (x & 0xFF000000) >> 24, whose mask can be made smaller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  // Such expressions arise normally from shift chains like (byte)(x >> 24).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  const Node *mask = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  if( mask->Opcode() == Op_AndI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      (t3 = phase->type(mask->in(2))->isa_int()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      t3->is_con() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    Node *x = mask->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    jint maskbits = t3->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
    // Convert to "(x >> shift) & (mask >> shift)"
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   915
    Node *shr_nomask = phase->transform( new RShiftINode(mask->in(1), in(2)) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
   916
    return new AndINode(shr_nomask, phase->intcon( maskbits >> shift));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  // Check for "(short[i] <<16)>>16" which simply sign-extends
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  const Node *shl = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  if( shl->Opcode() != Op_LShiftI ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  if( shift == 16 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
      (t3 = phase->type(shl->in(2))->isa_int()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
      t3->is_con(16) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
    Node *ld = shl->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    if( ld->Opcode() == Op_LoadS ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
      // Sign extension is just useless here.  Return a RShiftI of zero instead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
      // returning 'ld' directly.  We cannot return an old Node directly as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      // that is the job of 'Identity' calls and Identity calls only work on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
      // direct inputs ('ld' is an extra Node removed from 'this').  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      // combined optimization requires Identity only return direct inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
      set_req(1, ld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      set_req(2, phase->intcon(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    }
14129
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   937
    else if( can_reshape &&
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   938
             ld->Opcode() == Op_LoadUS &&
291ac612f0c6 8000805: JMM issue: short loads are non-atomic
vlivanov
parents: 13974
diff changeset
   939
             ld->outcnt() == 1 && ld->unique_out() == shl)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
      // Replace zero-extension-load with sign-extension-load
36830
ebc8b5e23f63 8152773: C2: LoadNode properties aren't preserved when converting between signed/unsigned variants
vlivanov
parents: 35551
diff changeset
   941
      return ld->as_Load()->convert_to_signed_load(*phase);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  // Check for "(byte[i] <<24)>>24" which simply sign-extends
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  if( shift == 24 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      (t3 = phase->type(shl->in(2))->isa_int()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
      t3->is_con(24) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
    Node *ld = shl->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    if( ld->Opcode() == Op_LoadB ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
      // Sign extension is just useless here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
      set_req(1, ld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
      set_req(2, phase->intcon(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
// A RShiftINode shifts its input2 right by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
   962
const Type* RShiftINode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  if( t1 == TypeInt::ZERO ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  if (t2 == TypeInt::INT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  const TypeInt *r1 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  const TypeInt *r2 = t2->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  // If the shift is a constant, just shift the bounds of the type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  // For example, if the shift is 31, we just propagate sign bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  if (r2->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    uint shift = r2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    shift &= BitsPerJavaInteger-1;  // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    // Shift by a multiple of 32 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    // Calculate reasonably aggressive bounds for the result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    // This is necessary if we are to correctly type things
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
    // like (x<<24>>24) == ((byte)x).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    jint lo = (jint)r1->_lo >> (jint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
    jint hi = (jint)r1->_hi >> (jint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    assert(lo <= hi, "must have valid bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    const TypeInt* ti = TypeInt::make(lo, hi, MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    // Make sure we get the sign-capture idiom correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
    if (shift == BitsPerJavaInteger-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
      if (r1->_lo >= 0) assert(ti == TypeInt::ZERO,    ">>31 of + is  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
      if (r1->_hi <  0) assert(ti == TypeInt::MINUS_1, ">>31 of - is -1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    return ti;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  if( !r1->is_con() || !r2->is_con() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  // Signed shift right
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  return TypeInt::make( r1->get_con() >> (r2->get_con()&31) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1017
Node* RShiftLNode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1018
  const TypeInt *ti = phase->type(in(2))->isa_int(); // Shift count is an int.
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1019
  return (ti && ti->is_con() && (ti->get_con() & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
// A RShiftLNode shifts its input2 right by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1024
const Type* RShiftLNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  if (t2 == TypeInt::INT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  const TypeLong *r1 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  const TypeInt  *r2 = t2->is_int (); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
  // If the shift is a constant, just shift the bounds of the type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  // For example, if the shift is 63, we just propagate sign bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
  if (r2->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    uint shift = r2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    shift &= (2*BitsPerJavaInteger)-1;  // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
    // Shift by a multiple of 64 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    // Calculate reasonably aggressive bounds for the result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    // This is necessary if we are to correctly type things
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    // like (x<<24>>24) == ((byte)x).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    jlong lo = (jlong)r1->_lo >> (jlong)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    jlong hi = (jlong)r1->_hi >> (jlong)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    assert(lo <= hi, "must have valid bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
    const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    // Make sure we get the sign-capture idiom correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
    if (shift == (2*BitsPerJavaInteger)-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
      if (r1->_lo >= 0) assert(tl == TypeLong::ZERO,    ">>63 of + is 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
      if (r1->_hi < 0)  assert(tl == TypeLong::MINUS_1, ">>63 of - is -1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
    return tl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  return TypeLong::LONG;                // Give up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1075
Node* URShiftINode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1076
  int shift = getShiftCon(phase, this, -1);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1077
  if ((shift & (BitsPerJavaInteger - 1)) == 0) return in(1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  // Check for "((x << LogBytesPerWord) + (wordSize-1)) >> LogBytesPerWord" which is just "x".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  // Happens during new-array length computation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  // Safe if 'x' is in the range [0..(max_int>>LogBytesPerWord)]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  Node *add = in(1);
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1083
  if (add->Opcode() == Op_AddI) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1084
    const TypeInt *t2 = phase->type(add->in(2))->isa_int();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1085
    if (t2 && t2->is_con(wordSize - 1) &&
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1086
        add->in(1)->Opcode() == Op_LShiftI) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1087
      // Check that shift_counts are LogBytesPerWord.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
      Node          *lshift_count   = add->in(1)->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
      const TypeInt *t_lshift_count = phase->type(lshift_count)->isa_int();
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1090
      if (t_lshift_count && t_lshift_count->is_con(LogBytesPerWord) &&
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1091
          t_lshift_count == phase->type(in(2))) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
        Node          *x   = add->in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
        const TypeInt *t_x = phase->type(x)->isa_int();
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1094
        if (t_x != NULL && 0 <= t_x->_lo && t_x->_hi <= (max_jint>>LogBytesPerWord)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
          return x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
  return (phase->type(in(2))->higher_equal(TypeInt::ZERO)) ? in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
Node *URShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1106
  int con = maskShiftAmount(phase, this, BitsPerJavaInteger);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1107
  if (con == 0) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1108
    return NULL;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1109
  }
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1110
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
  // We'll be wanting the right-shift amount as a mask of that many bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  const int mask = right_n_bits(BitsPerJavaInteger - con);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  int in1_op = in(1)->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  // Check for ((x>>>a)>>>b) and replace with (x>>>(a+b)) when a+b < 32
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  if( in1_op == Op_URShiftI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    const TypeInt *t12 = phase->type( in(1)->in(2) )->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
    if( t12 && t12->is_con() ) { // Right input is a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
      assert( in(1) != in(1)->in(1), "dead loop in URShiftINode::Ideal" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      const int con2 = t12->get_con() & 31; // Shift count is always masked
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
      const int con3 = con+con2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
      if( con3 < 32 )           // Only merge shifts if total is < 32
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1124
        return new URShiftINode( in(1)->in(1), phase->intcon(con3) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  // Check for ((x << z) + Y) >>> z.  Replace with x + con>>>z
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  // If Q is "X << z" the rounding is useless.  Look for patterns like
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  Node *add = in(1);
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1133
  const TypeInt *t2 = phase->type(in(2))->isa_int();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1134
  if (in1_op == Op_AddI) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    Node *lshl = add->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
    if( lshl->Opcode() == Op_LShiftI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
        phase->type(lshl->in(2)) == t2 ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1138
      Node *y_z = phase->transform( new URShiftINode(add->in(2),in(2)) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1139
      Node *sum = phase->transform( new AddINode( lshl->in(1), y_z ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1140
      return new AndINode( sum, phase->intcon(mask) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  // Check for (x & mask) >>> z.  Replace with (x >>> z) & (mask >>> z)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  // This shortens the mask.  Also, if we are extracting a high byte and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  // storing it to a buffer, the mask will be removed completely.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  Node *andi = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  if( in1_op == Op_AndI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
    const TypeInt *t3 = phase->type( andi->in(2) )->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    if( t3 && t3->is_con() ) { // Right input is a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
      jint mask2 = t3->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      mask2 >>= con;  // *signed* shift downward (high-order zeroes do not help)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1153
      Node *newshr = phase->transform( new URShiftINode(andi->in(1), in(2)) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1154
      return new AndINode(newshr, phase->intcon(mask2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
      // The negative values are easier to materialize than positive ones.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
      // A typical case from address arithmetic is ((x & ~15) >> 4).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      // It's better to change that to ((x >> 4) & ~0) versus
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
      // ((x >> 4) & 0x0FFFFFFF).  The difference is greatest in LP64.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  // Check for "(X << z ) >>> z" which simply zero-extends
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  Node *shl = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  if( in1_op == Op_LShiftI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
      phase->type(shl->in(2)) == t2 )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1166
    return new AndINode( shl->in(1), phase->intcon(mask) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
// A URShiftINode shifts its input2 right by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1173
const Type* URShiftINode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  // (This is a near clone of RShiftINode::Value.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  if( t1 == TypeInt::ZERO ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  if (t2 == TypeInt::INT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  const TypeInt *r1 = t1->is_int();     // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
  const TypeInt *r2 = t2->is_int();     // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  if (r2->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
    uint shift = r2->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    shift &= BitsPerJavaInteger-1;  // semantics of Java shifts
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    // Shift by a multiple of 32 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    // Calculate reasonably aggressive bounds for the result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
    jint lo = (juint)r1->_lo >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    jint hi = (juint)r1->_hi >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    if (r1->_hi >= 0 && r1->_lo < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
      // If the type has both negative and positive values,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
      // there are two separate sub-domains to worry about:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      // The positive half and the negative half.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      jint neg_lo = lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
      jint neg_hi = (juint)-1 >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
      jint pos_lo = (juint) 0 >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      jint pos_hi = hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
      lo = MIN2(neg_lo, pos_lo);  // == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
      hi = MAX2(neg_hi, pos_hi);  // == -1 >>> shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    assert(lo <= hi, "must have valid bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    const TypeInt* ti = TypeInt::make(lo, hi, MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    // Make sure we get the sign-capture idiom correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
    if (shift == BitsPerJavaInteger-1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
      if (r1->_lo >= 0) assert(ti == TypeInt::ZERO, ">>>31 of + is 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
      if (r1->_hi < 0)  assert(ti == TypeInt::ONE,  ">>>31 of - is +1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
    return ti;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  // Do not support shifted oops in info for GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  // else if( t1->base() == Type::InstPtr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
  //   const TypeInstPtr *o = t1->is_instptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
  //   if( t1->singleton() )
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 23528
diff changeset
  1234
  //     return TypeInt::make( ((uint32_t)o->const_oop() + o->_offset) >> shift );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  // else if( t1->base() == Type::KlassPtr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  //   const TypeKlassPtr *o = t1->is_klassptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  //   if( t1->singleton() )
24425
53764d2358f9 8041415: remove port.{cpp,hpp} files
zgu
parents: 23528
diff changeset
  1239
  //     return TypeInt::make( ((uint32_t)o->const_oop() + o->_offset) >> shift );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
//------------------------------Identity---------------------------------------
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1247
Node* URShiftLNode::Identity(PhaseGVN* phase) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1248
  return ((getShiftCon(phase, this, -1) & (BitsPerJavaLong - 1)) == 0) ? in(1) : this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
Node *URShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1253
  int con = maskShiftAmount(phase, this, BitsPerJavaLong);
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1254
  if (con == 0) {
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1255
    return NULL;
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1256
  }
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1257
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
  // We'll be wanting the right-shift amount as a mask of that many bits
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 27471
diff changeset
  1259
  const jlong mask = jlong(max_julong >> con);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  // Check for ((x << z) + Y) >>> z.  Replace with x + con>>>z
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  // If Q is "X << z" the rounding is useless.  Look for patterns like
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  // ((X<<Z) + Y) >>> Z  and replace with (X + Y>>>Z) & Z-mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  Node *add = in(1);
46277
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1266
  const TypeInt *t2 = phase->type(in(2))->isa_int();
73607b4788cb 8173470: [C2] Mask shift operands in ideal graph.
goetz
parents: 41323
diff changeset
  1267
  if (add->Opcode() == Op_AddL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    Node *lshl = add->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
    if( lshl->Opcode() == Op_LShiftL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
        phase->type(lshl->in(2)) == t2 ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1271
      Node *y_z = phase->transform( new URShiftLNode(add->in(2),in(2)) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1272
      Node *sum = phase->transform( new AddLNode( lshl->in(1), y_z ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1273
      return new AndLNode( sum, phase->longcon(mask) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
  // Check for (x & mask) >>> z.  Replace with (x >>> z) & (mask >>> z)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
  // This shortens the mask.  Also, if we are extracting a high byte and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
  // storing it to a buffer, the mask will be removed completely.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
  Node *andi = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
  if( andi->Opcode() == Op_AndL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
    const TypeLong *t3 = phase->type( andi->in(2) )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
    if( t3 && t3->is_con() ) { // Right input is a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
      jlong mask2 = t3->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      mask2 >>= con;  // *signed* shift downward (high-order zeroes do not help)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1286
      Node *newshr = phase->transform( new URShiftLNode(andi->in(1), in(2)) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1287
      return new AndLNode(newshr, phase->longcon(mask2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
  // Check for "(X << z ) >>> z" which simply zero-extends
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  Node *shl = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
  if( shl->Opcode() == Op_LShiftL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
      phase->type(shl->in(2)) == t2 )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24425
diff changeset
  1295
    return new AndLNode( shl->in(1), phase->longcon(mask) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
// A URShiftINode shifts its input2 right by input1 amount.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35155
diff changeset
  1302
const Type* URShiftLNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
  // (This is a near clone of RShiftLNode::Value.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
  // Left input is ZERO ==> the result is ZERO.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  if( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  // Shift by zero does nothing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
  if( t2 == TypeInt::ZERO ) return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
  // Either input is BOTTOM ==> the result is BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
  if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  if (t2 == TypeInt::INT)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  const TypeLong *r1 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  const TypeInt  *r2 = t2->is_int (); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  if (r2->is_con()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    uint shift = r2->get_con();
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
  1327
    shift &= BitsPerJavaLong - 1;  // semantics of Java shifts
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    // Shift by a multiple of 64 does nothing:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    if (shift == 0)  return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    // Calculate reasonably aggressive bounds for the result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
    jlong lo = (julong)r1->_lo >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    jlong hi = (julong)r1->_hi >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
    if (r1->_hi >= 0 && r1->_lo < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
      // If the type has both negative and positive values,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
      // there are two separate sub-domains to worry about:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
      // The positive half and the negative half.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
      jlong neg_lo = lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
      jlong neg_hi = (julong)-1 >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
      jlong pos_lo = (julong) 0 >> (juint)shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
      jlong pos_hi = hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
      //lo = MIN2(neg_lo, pos_lo);  // == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
      lo = neg_lo < pos_lo ? neg_lo : pos_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
      //hi = MAX2(neg_hi, pos_hi);  // == -1 >>> shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
      hi = neg_hi > pos_hi ? neg_hi : pos_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
    assert(lo <= hi, "must have valid bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
    const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
    // Make sure we get the sign-capture idiom correct.
2023
10d955a8d972 6795362: 32bit server compiler leads to wrong results on solaris-x86
twisti
parents: 2022
diff changeset
  1350
    if (shift == BitsPerJavaLong - 1) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
      if (r1->_hi < 0)  assert(tl == TypeLong::ONE,  ">>>63 of - is +1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
    return tl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  return TypeLong::LONG;                // Give up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
}
41323
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1360
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1361
//=============================================================================
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1362
//------------------------------Value------------------------------------------
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1363
const Type* FmaDNode::Value(PhaseGVN* phase) const {
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1364
  const Type *t1 = phase->type(in(1));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1365
  if (t1 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1366
  if (t1->base() != Type::DoubleCon) return Type::DOUBLE;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1367
  const Type *t2 = phase->type(in(2));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1368
  if (t2 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1369
  if (t2->base() != Type::DoubleCon) return Type::DOUBLE;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1370
  const Type *t3 = phase->type(in(3));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1371
  if (t3 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1372
  if (t3->base() != Type::DoubleCon) return Type::DOUBLE;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1373
#ifndef __STDC_IEC_559__
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1374
  return Type::DOUBLE;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1375
#else
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1376
  double d1 = t1->getd();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1377
  double d2 = t2->getd();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1378
  double d3 = t3->getd();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1379
  return TypeD::make(fma(d1, d2, d3));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1380
#endif
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1381
}
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1382
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1383
//=============================================================================
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1384
//------------------------------Value------------------------------------------
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1385
const Type* FmaFNode::Value(PhaseGVN* phase) const {
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1386
  const Type *t1 = phase->type(in(1));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1387
  if (t1 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1388
  if (t1->base() != Type::FloatCon) return Type::FLOAT;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1389
  const Type *t2 = phase->type(in(2));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1390
  if (t2 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1391
  if (t2->base() != Type::FloatCon) return Type::FLOAT;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1392
  const Type *t3 = phase->type(in(3));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1393
  if (t3 == Type::TOP) return Type::TOP;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1394
  if (t3->base() != Type::FloatCon) return Type::FLOAT;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1395
#ifndef __STDC_IEC_559__
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1396
  return Type::FLOAT;
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1397
#else
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1398
  float f1 = t1->getf();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1399
  float f2 = t2->getf();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1400
  float f3 = t3->getf();
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1401
  return TypeF::make(fma(f1, f2, f3));
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1402
#endif
ddd5600d4762 8154122: Intrinsify fused mac operations
vdeshpande
parents: 36830
diff changeset
  1403
}