src/hotspot/share/opto/subnode.cpp
author thartmann
Tue, 25 Sep 2018 14:16:33 +0200
changeset 51863 bc38c75eed57
parent 51666 7e6b86eb7914
child 52143 ad6384355aa3
permissions -rw-r--r--
8210152: Optimize integer divisible by power-of-2 check Summary: Integer conditional negation operation before zero check is eliminated Reviewed-by: kvn, thartmann Contributed-by: pengfei.li@arm.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49816
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 48089
diff changeset
     2
 * Copyright (c) 1997, 2018, 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: 4645
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4645
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: 4645
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 "compiler/compileLog.hpp"
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
    27
#include "gc/shared/barrierSet.hpp"
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
    28
#include "gc/shared/c2/barrierSetC2.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/addnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/callnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "opto/cfgnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "opto/loopnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "opto/matcher.hpp"
23528
8f1a7f5e8066 8001532: C2 node files refactoring
morris
parents: 22911
diff changeset
    35
#include "opto/movenode.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "opto/mulnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "opto/opcodes.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "opto/subnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Portions of code courtesy of Clifford Click
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Optimization - Graph Style
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
#include "math.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//------------------------------Identity---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// If right input is a constant 0, return the left input.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
    51
Node* SubNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  assert(in(1) != this, "Must already have called Value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  assert(in(2) != this, "Must already have called Value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Remove double negation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  const Type *zero = add_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if( phase->type( in(1) )->higher_equal( zero ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      in(2)->Opcode() == Opcode() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    return in(2)->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
758
38c168fb8c79 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 360
diff changeset
    63
  // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  if( in(1)->Opcode() == Op_AddI ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    if( phase->eqv(in(1)->in(2),in(2)) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      return in(1)->in(1);
758
38c168fb8c79 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 360
diff changeset
    67
    if (phase->eqv(in(1)->in(1),in(2)))
38c168fb8c79 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 360
diff changeset
    68
      return in(1)->in(2);
38c168fb8c79 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 360
diff changeset
    69
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    // Also catch: "(X + Opaque2(Y)) - Y".  In this case, 'Y' is a loop-varying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    // trip counter and X is likely to be loop-invariant (that's how O2 Nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // are originally used, although the optimizer sometimes jiggers things).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    // This folding through an O2 removes a loop-exit use of a loop-varying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // value and generally lowers register pressure in and around the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        phase->eqv(in(1)->in(2)->in(1),in(2)) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      return in(1)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// A subtract node differences it's two inputs.
24479
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
    85
const Type* SubNode::Value_common(PhaseTransform *phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Not correct for SubFnode and AddFNode (must check for infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Equal?  Subtract is zero
11446
fd87432a895b 7128352: assert(obj_node == obj) failed
kvn
parents: 9966
diff changeset
    96
  if (in1->eqv_uncast(in2))  return add_id();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
24479
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   102
  return NULL;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   103
}
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   104
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
   105
const Type* SubNode::Value(PhaseGVN* phase) const {
24479
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   106
  const Type* t = Value_common(phase);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   107
  if (t != NULL) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   108
    return t;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   109
  }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   110
  const Type* t1 = phase->type(in(1));
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   111
  const Type* t2 = phase->type(in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return sub(t1,t2);            // Local flavor of type subtraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
//------------------------------Helper function--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
static bool ok_to_convert(Node* inc, Node* iv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // Do not collapse (x+c0)-y if "+" is a loop increment, because the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // "-" is loop invariant and collapsing extends the live-range of "x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // to overlap with the "+", forcing another register to be used in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // the loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // This test will be clearer with '&&' (apply DeMorgan's rule)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // but I like the early cutouts that happen here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    const PhiNode *phi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if( ( !inc->in(1)->is_Phi() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
          !(phi=inc->in(1)->as_Phi()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          phi->is_copy() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
          !phi->region()->is_CountedLoop() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
          inc != phi->region()->as_CountedLoop()->incr() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
       &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        // Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        // because "x" maybe invariant.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        ( !iv->is_loop_iv() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  Node *in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  Node *in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  uint op1 = in1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  uint op2 = in2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   152
      ( ( op1 == Op_AddI || op1 == Op_SubI ) &&
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   153
        ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   154
          phase->eqv( in1->in(1), in1  ) || phase->eqv( in1->in(2), in1 ) ) ) )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    assert(false, "dead loop in SubINode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  const Type *t2 = phase->type( in2 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if( t2 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if( t2->base() == Type::Int ){        // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    const TypeInt *i = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if( i->is_con() )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   164
      return new AddINode(in1, phase->intcon(-i->get_con()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Convert "(x+c0) - y" into (x-y) + c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Do not collapse (x+c0)-y if "+" is a loop increment or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // if "y" is a loop induction variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    const Type *tadd = phase->type( in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    if( tadd->singleton() && tadd != Type::TOP ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   173
      Node *sub2 = phase->transform( new SubINode( in1->in(1), in2 ));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   174
      return new AddINode( sub2, in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // Convert "x - (y+c0)" into "(x-y) - c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // Need the same check as in above optimization but reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  if (op2 == Op_AddI && ok_to_convert(in2, in1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    Node* in21 = in2->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    Node* in22 = in2->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    const TypeInt* tcon = phase->type(in22)->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    if (tcon != NULL && tcon->is_con()) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   186
      Node* sub2 = phase->transform( new SubINode(in1, in21) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      Node* neg_c0 = phase->intcon(- tcon->get_con());
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   188
      return new AddINode(sub2, neg_c0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  const Type *t1 = phase->type( in1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if( t1 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if( ( op2 == Op_AddI || op2 == Op_SubI ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        phase->eqv( in2->in(1), in2  ) || phase->eqv( in2->in(2), in2  ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    assert(false, "dead loop in SubINode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  if( op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      phase->eqv( in1, in2->in(1) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   206
    return new SubINode( phase->intcon(0),in2->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // Convert "(x-y) - x" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if( op1 == Op_SubI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      phase->eqv( in1->in(1), in2 ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   210
    return new SubINode( phase->intcon(0),in1->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Convert "x - (y+x)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if( op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      phase->eqv( in1, in2->in(2) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   214
    return new SubINode( phase->intcon(0),in2->in(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Convert "0 - (x-y)" into "y-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if( t1 == TypeInt::ZERO && op2 == Op_SubI )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   218
    return new SubINode( in2->in(2), in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Convert "0 - (x+con)" into "-con-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  jint con;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      (con = in2->in(2)->find_int_con(0)) != 0 )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   224
    return new SubINode( phase->intcon(-con), in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // Convert "(X+A) - (X+B)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   228
    return new SubINode( in1->in(2), in2->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Convert "(A+X) - (B+X)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   232
    return new SubINode( in1->in(1), in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   234
  // Convert "(A+X) - (X+B)" into "A - B"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   235
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   236
    return new SubINode( in1->in(1), in2->in(2) );
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   237
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   238
  // Convert "(X+A) - (B+X)" into "A - B"
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   239
  if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   240
    return new SubINode( in1->in(2), in2->in(1) );
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 1058
diff changeset
   241
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // nicer to optimize than subtract.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  if( op2 == Op_SubI && in2->outcnt() == 1) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   245
    Node *add1 = phase->transform( new AddINode( in1, in2->in(2) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   246
    return new SubINode( add1, in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
// A subtract node differences it's two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  const TypeInt *r0 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  const TypeInt *r1 = t2->is_int();
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35146
diff changeset
   257
  int32_t lo = java_subtract(r0->_lo, r1->_hi);
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35146
diff changeset
   258
  int32_t hi = java_subtract(r0->_hi, r1->_lo);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // We next check for 32-bit overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // If that happens, we just assume all integers are possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
       ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
       ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  else                          // Overflow; assume all integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    return TypeInt::INT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  Node *in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  Node *in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  uint op1 = in1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  uint op2 = in2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   282
      ( ( op1 == Op_AddL || op1 == Op_SubL ) &&
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   283
        ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 38698
diff changeset
   284
          phase->eqv( in1->in(1), in1  ) || phase->eqv( in1->in(2), in1  ) ) ) )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    assert(false, "dead loop in SubLNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  if( phase->type( in2 ) == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  const TypeLong *i = phase->type( in2 )->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  if( i &&                      // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      i->is_con() )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   293
    return new AddLNode(in1, phase->longcon(-i->get_con()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // Convert "(x+c0) - y" into (x-y) + c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // Do not collapse (x+c0)-y if "+" is a loop increment or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // if "y" is a loop induction variable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    Node *in11 = in1->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    const Type *tadd = phase->type( in1->in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    if( tadd->singleton() && tadd != Type::TOP ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   302
      Node *sub2 = phase->transform( new SubLNode( in11, in2 ));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   303
      return new AddLNode( sub2, in1->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  // Convert "x - (y+c0)" into "(x-y) - c0"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // Need the same check as in above optimization but reversed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  if (op2 == Op_AddL && ok_to_convert(in2, in1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    Node* in21 = in2->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    Node* in22 = in2->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    const TypeLong* tcon = phase->type(in22)->isa_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    if (tcon != NULL && tcon->is_con()) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   314
      Node* sub2 = phase->transform( new SubLNode(in1, in21) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      Node* neg_c0 = phase->longcon(- tcon->get_con());
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   316
      return new AddLNode(sub2, neg_c0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  const Type *t1 = phase->type( in1 );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  if( t1 == Type::TOP ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // Check for dead loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  if( ( op2 == Op_AddL || op2 == Op_SubL ) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        phase->eqv( in2->in(1), in2  ) || phase->eqv( in2->in(2), in2  ) ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    assert(false, "dead loop in SubLNode::Ideal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  if( op2 == Op_AddL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      phase->eqv( in1, in2->in(1) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   334
    return new SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // Convert "x - (y+x)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  if( op2 == Op_AddL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      phase->eqv( in1, in2->in(2) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   338
    return new SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // Convert "0 - (x-y)" into "y-x"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   342
    return new SubLNode( in2->in(2), in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // Convert "(X+A) - (X+B)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   346
    return new SubLNode( in1->in(2), in2->in(2) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  // Convert "(A+X) - (B+X)" into "A - B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   350
    return new SubLNode( in1->in(1), in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // Convert "A-(B-C)" into (A+C)-B"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  if( op2 == Op_SubL && in2->outcnt() == 1) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   354
    Node *add1 = phase->transform( new AddLNode( in1, in2->in(2) ) );
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   355
    return new SubLNode( add1, in2->in(1) );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
// A subtract node differences it's two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  const TypeLong *r0 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  const TypeLong *r1 = t2->is_long();
35155
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35146
diff changeset
   366
  jlong lo = java_subtract(r0->_lo, r1->_hi);
db692d3ebbcc 8145096: Undefined behaviour in HotSpot
aph
parents: 35146
diff changeset
   367
  jlong hi = java_subtract(r0->_hi, r1->_lo);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // We next check for 32-bit overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // If that happens, we just assume all integers are possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  if( (((r0->_lo ^ r1->_hi) >= 0) ||    // lo ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
       ((r0->_lo ^      lo) >= 0)) &&   // lo results have same signs AND
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      (((r0->_hi ^ r1->_lo) >= 0) ||    // hi ends have same signs OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
       ((r0->_hi ^      hi) >= 0)) )    // hi results have same signs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  else                          // Overflow; assume all integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    return TypeLong::LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
// A subtract node differences its two inputs.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
   383
const Type* SubFPNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  // if both operands are infinity of same sign, the result is NaN; do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  // not replace with zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  if( (t1->is_finite() && t2->is_finite()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    if( phase->eqv(in1, in2) ) return add_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  // Either input is BOTTOM ==> the result is the local BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  const Type *bot = bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  if( (t1 == bot) || (t2 == bot) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
      (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    return bot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  return sub(t1,t2);            // Local flavor of type subtraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  if( t2->base() == Type::FloatCon ) {  // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // Not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    if( in(2)->is_Add() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
        phase->eqv(in(1),in(2)->in(1) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   422
      return new SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  //if( phase->type(in(1)) == TypeF::ZERO )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  //return new (phase->C, 2) NegFNode(in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// A subtract node differences its two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // no folding if one of operands is infinity or NaN, do not do constant folding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    return TypeF::make( t1->getf() - t2->getf() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  else if( g_isnan(t1->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  else if( g_isnan(t2->getf()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    return Type::FLOAT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  const Type *t2 = phase->type( in(2) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  // Convert "x-c0" into "x+ -c0".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  if( t2->base() == Type::DoubleCon ) { // Might be bottom or top...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // Not associative because of boundary conditions (infinity)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    // Convert "x - (x+y)" into "-y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    if( in(2)->is_Add() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
        phase->eqv(in(1),in(2)->in(1) ) )
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   465
      return new SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  //if( phase->type(in(1)) == TypeD::ZERO )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  //return new (phase->C, 2) NegDNode(in(2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
// A subtract node differences its two inputs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  // no folding if one of operands is infinity or NaN, do not do constant folding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    return TypeD::make( t1->getd() - t2->getd() );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  else if( g_isnan(t1->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    return t1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  else if( g_isnan(t2->getd()) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    return t2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
// Unlike SubNodes, compare must still flatten return value to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
// range -1, 0, 1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
// And optimizations like those for (X + Y) - X fail if overflow happens.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
   499
Node* CmpNode::Identity(PhaseGVN* phase) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   503
#ifndef PRODUCT
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   504
//----------------------------related------------------------------------------
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   505
// Related nodes of comparison nodes include all data inputs (until hitting a
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   506
// control boundary) as well as all outputs until and including control nodes
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   507
// as well as their projections. In compact mode, data inputs till depth 1 and
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   508
// all outputs till depth 1 are considered.
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   509
void CmpNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   510
  if (compact) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   511
    this->collect_nodes(in_rel, 1, false, true);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   512
    this->collect_nodes(out_rel, -1, false, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   513
  } else {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   514
    this->collect_nodes_in_all_data(in_rel, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   515
    this->collect_nodes_out_all_ctrl_boundary(out_rel);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   516
    // Now, find all control nodes in out_rel, and include their projections
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   517
    // and projection targets (if any) in the result.
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   518
    GrowableArray<Node*> proj(Compile::current()->unique());
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   519
    for (GrowableArrayIterator<Node*> it = out_rel->begin(); it != out_rel->end(); ++it) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   520
      Node* n = *it;
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   521
      if (n->is_CFG() && !n->is_Proj()) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   522
        // Assume projections and projection targets are found at levels 1 and 2.
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   523
        n->collect_nodes(&proj, -2, false, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   524
        for (GrowableArrayIterator<Node*> p = proj.begin(); p != proj.end(); ++p) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   525
          out_rel->append_if_missing(*p);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   526
        }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   527
        proj.clear();
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   528
      }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   529
    }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   530
  }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   531
}
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   532
#endif
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
   533
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
//------------------------------cmp--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
// Simplify a CmpI (compare 2 integers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  const TypeInt *r0 = t1->is_int(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  const TypeInt *r1 = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  if( r0->_hi < r1->_lo )       // Range is always low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  else if( r0->_lo > r1->_hi )  // Range is always high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  else if( r0->is_con() && r1->is_con() ) { // comparing constants?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    assert(r0->get_con() == r1->get_con(), "must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    return TypeInt::CC_EQ;      // Equal results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  } else if( r0->_hi == r1->_lo ) // Range is never high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  else if( r0->_lo == r1->_hi ) // Range is never low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  return TypeInt::CC;           // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
// Simplify a CmpU (compare 2 integers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  assert(!t1->isa_ptr(), "obsolete usage of CmpU");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // comparing two unsigned ints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  const TypeInt *r0 = t1->is_int();   // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  const TypeInt *r1 = t2->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  // Current installed version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  // Compare ranges for non-overlap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  juint lo0 = r0->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  juint hi0 = r0->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  juint lo1 = r1->_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  juint hi1 = r1->_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // If either one has both negative and positive values,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  // it therefore contains both 0 and -1, and since [0..-1] is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  // full unsigned range, the type must act as an unsigned bottom.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  bool bot0 = ((jint)(lo0 ^ hi0) < 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  bool bot1 = ((jint)(lo1 ^ hi1) < 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  if (bot0 || bot1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    // All unsigned values are LE -1 and GE 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    if (lo0 == 0 && hi0 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      return TypeInt::CC_LE;            //   0 <= bot
38698
2f5f325d4e6d 8154831: CastII/ConvI2L for a range check is prematurely eliminated
vlivanov
parents: 38018
diff changeset
   583
    } else if ((jint)lo0 == -1 && (jint)hi0 == -1) {
2f5f325d4e6d 8154831: CastII/ConvI2L for a range check is prematurely eliminated
vlivanov
parents: 38018
diff changeset
   584
      return TypeInt::CC_GE;            // -1 >= bot
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    } else if (lo1 == 0 && hi1 == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      return TypeInt::CC_GE;            // bot >= 0
38698
2f5f325d4e6d 8154831: CastII/ConvI2L for a range check is prematurely eliminated
vlivanov
parents: 38018
diff changeset
   587
    } else if ((jint)lo1 == -1 && (jint)hi1 == -1) {
2f5f325d4e6d 8154831: CastII/ConvI2L for a range check is prematurely eliminated
vlivanov
parents: 38018
diff changeset
   588
      return TypeInt::CC_LE;            // bot <= -1
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    // We can use ranges of the form [lo..hi] if signs are the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    // results are reversed, '-' > '+' for unsigned compare
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    if (hi0 < lo1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
      return TypeInt::CC_LT;            // smaller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    } else if (lo0 > hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      return TypeInt::CC_GT;            // greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    } else if (hi0 == lo1 && lo0 == hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
      return TypeInt::CC_EQ;            // Equal results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    } else if (lo0 >= hi1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
      return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    } else if (hi0 <= lo1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      // Check for special case in Hashtable::get.  (See below.)
13205
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   604
      if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
        return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // Check for special case in Hashtable::get - the hash index is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  // mod'ed to the table size so the following range check is useless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // to be positive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  // (This is a gross hack, since the sub method never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  // looks at the structure of the node in any other case.)
13205
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   615
  if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  return TypeInt::CC;                   // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
   620
const Type* CmpUNode::Value(PhaseGVN* phase) const {
24479
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   621
  const Type* t = SubNode::Value_common(phase);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   622
  if (t != NULL) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   623
    return t;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   624
  }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   625
  const Node* in1 = in(1);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   626
  const Node* in2 = in(2);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   627
  const Type* t1 = phase->type(in1);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   628
  const Type* t2 = phase->type(in2);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   629
  assert(t1->isa_int(), "CmpU has only Int type inputs");
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   630
  if (t2 == TypeInt::INT) { // Compare to bottom?
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   631
    return bottom_type();
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   632
  }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   633
  uint in1_op = in1->Opcode();
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   634
  if (in1_op == Op_AddI || in1_op == Op_SubI) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   635
    // The problem rise when result of AddI(SubI) may overflow
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   636
    // signed integer value. Let say the input type is
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   637
    // [256, maxint] then +128 will create 2 ranges due to
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   638
    // overflow: [minint, minint+127] and [384, maxint].
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   639
    // But C2 type system keep only 1 type range and as result
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   640
    // it use general [minint, maxint] for this case which we
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   641
    // can't optimize.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   642
    //
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   643
    // Make 2 separate type ranges based on types of AddI(SubI) inputs
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   644
    // and compare results of their compare. If results are the same
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   645
    // CmpU node can be optimized.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   646
    const Node* in11 = in1->in(1);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   647
    const Node* in12 = in1->in(2);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   648
    const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   649
    const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   650
    // Skip cases when input types are top or bottom.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   651
    if ((t11 != Type::TOP) && (t11 != TypeInt::INT) &&
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   652
        (t12 != Type::TOP) && (t12 != TypeInt::INT)) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   653
      const TypeInt *r0 = t11->is_int();
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   654
      const TypeInt *r1 = t12->is_int();
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   655
      jlong lo_r0 = r0->_lo;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   656
      jlong hi_r0 = r0->_hi;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   657
      jlong lo_r1 = r1->_lo;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   658
      jlong hi_r1 = r1->_hi;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   659
      if (in1_op == Op_SubI) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   660
        jlong tmp = hi_r1;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   661
        hi_r1 = -lo_r1;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   662
        lo_r1 = -tmp;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   663
        // Note, for substructing [minint,x] type range
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   664
        // long arithmetic provides correct overflow answer.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   665
        // The confusion come from the fact that in 32-bit
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   666
        // -minint == minint but in 64-bit -minint == maxint+1.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   667
      }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   668
      jlong lo_long = lo_r0 + lo_r1;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   669
      jlong hi_long = hi_r0 + hi_r1;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   670
      int lo_tr1 = min_jint;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   671
      int hi_tr1 = (int)hi_long;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   672
      int lo_tr2 = (int)lo_long;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   673
      int hi_tr2 = max_jint;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   674
      bool underflow = lo_long != (jlong)lo_tr2;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   675
      bool overflow  = hi_long != (jlong)hi_tr1;
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   676
      // Use sub(t1, t2) when there is no overflow (one type range)
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   677
      // or when both overflow and underflow (too complex).
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   678
      if ((underflow != overflow) && (hi_tr1 < lo_tr2)) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   679
        // Overflow only on one boundary, compare 2 separate type ranges.
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   680
        int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   681
        const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   682
        const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   683
        const Type* cmp1 = sub(tr1, t2);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   684
        const Type* cmp2 = sub(tr2, t2);
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   685
        if (cmp1 == cmp2) {
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   686
          return cmp1; // Hit!
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   687
        }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   688
      }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   689
    }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   690
  }
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   691
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   692
  return sub(t1, t2);            // Local flavor of type subtraction
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   693
}
20eb4c752fb5 8042786: Proper fix for 8032566
kvn
parents: 24424
diff changeset
   694
13205
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   695
bool CmpUNode::is_index_range_check() const {
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   696
  // Check for the "(X ModI Y) CmpU Y" shape
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   697
  return (in(1)->Opcode() == Op_ModI &&
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   698
          in(1)->in(2)->eqv_uncast(in(2)));
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   699
}
5495b63764bf 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 12945
diff changeset
   700
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
//------------------------------Idealize---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    switch (in(1)->Opcode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    case Op_CmpL3:              // Collapse a CmpL3/CmpI into a CmpL
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   706
      return new CmpLNode(in(1)->in(1),in(1)->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    case Op_CmpF3:              // Collapse a CmpF3/CmpI into a CmpF
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   708
      return new CmpFNode(in(1)->in(1),in(1)->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    case Op_CmpD3:              // Collapse a CmpD3/CmpI into a CmpD
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
   710
      return new CmpDNode(in(1)->in(1),in(1)->in(2));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    //case Op_SubI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      // If (x - y) cannot overflow, then ((x - y) <?> 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
      // can be turned into (x <?> y).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
      // This is handled (with more general cases) by Ideal_sub_algebra.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  return NULL;                  // No change
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
// Simplify a CmpL (compare 2 longs ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  const TypeLong *r0 = t1->is_long(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  const TypeLong *r1 = t2->is_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  if( r0->_hi < r1->_lo )       // Range is always low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  else if( r0->_lo > r1->_hi )  // Range is always high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
    return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  else if( r0->is_con() && r1->is_con() ) { // comparing constants?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    assert(r0->get_con() == r1->get_con(), "must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    return TypeInt::CC_EQ;      // Equal results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  } else if( r0->_hi == r1->_lo ) // Range is never high?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    return TypeInt::CC_LE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  else if( r0->_lo == r1->_hi ) // Range is never low?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    return TypeInt::CC_GE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  return TypeInt::CC;           // else use worst case results
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
45965
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   743
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   744
// Simplify a CmpUL (compare 2 unsigned longs) node, based on local information.
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   745
// If both inputs are constants, compare them.
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   746
const Type* CmpULNode::sub(const Type* t1, const Type* t2) const {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   747
  assert(!t1->isa_ptr(), "obsolete usage of CmpUL");
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   748
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   749
  // comparing two unsigned longs
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   750
  const TypeLong* r0 = t1->is_long();   // Handy access
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   751
  const TypeLong* r1 = t2->is_long();
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   752
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   753
  // Current installed version
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   754
  // Compare ranges for non-overlap
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   755
  julong lo0 = r0->_lo;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   756
  julong hi0 = r0->_hi;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   757
  julong lo1 = r1->_lo;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   758
  julong hi1 = r1->_hi;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   759
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   760
  // If either one has both negative and positive values,
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   761
  // it therefore contains both 0 and -1, and since [0..-1] is the
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   762
  // full unsigned range, the type must act as an unsigned bottom.
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   763
  bool bot0 = ((jlong)(lo0 ^ hi0) < 0);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   764
  bool bot1 = ((jlong)(lo1 ^ hi1) < 0);
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   765
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   766
  if (bot0 || bot1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   767
    // All unsigned values are LE -1 and GE 0.
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   768
    if (lo0 == 0 && hi0 == 0) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   769
      return TypeInt::CC_LE;            //   0 <= bot
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   770
    } else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   771
      return TypeInt::CC_GE;            // -1 >= bot
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   772
    } else if (lo1 == 0 && hi1 == 0) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   773
      return TypeInt::CC_GE;            // bot >= 0
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   774
    } else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   775
      return TypeInt::CC_LE;            // bot <= -1
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   776
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   777
  } else {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   778
    // We can use ranges of the form [lo..hi] if signs are the same.
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   779
    assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   780
    // results are reversed, '-' > '+' for unsigned compare
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   781
    if (hi0 < lo1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   782
      return TypeInt::CC_LT;            // smaller
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   783
    } else if (lo0 > hi1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   784
      return TypeInt::CC_GT;            // greater
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   785
    } else if (hi0 == lo1 && lo0 == hi1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   786
      return TypeInt::CC_EQ;            // Equal results
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   787
    } else if (lo0 >= hi1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   788
      return TypeInt::CC_GE;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   789
    } else if (hi0 <= lo1) {
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   790
      return TypeInt::CC_LE;
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   791
    }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   792
  }
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   793
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   794
  return TypeInt::CC;                   // else use worst case results
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   795
}
e29c1363af9a 8173770: Image conversion improvements
thartmann
parents: 38698
diff changeset
   796
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
//------------------------------sub--------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
// Simplify an CmpP (compare 2 pointers) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
// If both inputs are constants, compare them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  const TypePtr *r0 = t1->is_ptr(); // Handy access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  const TypePtr *r1 = t2->is_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  // Undefined inputs makes for an undefined result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  if( TypePtr::above_centerline(r0->_ptr) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      TypePtr::above_centerline(r1->_ptr) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  if (r0 == r1 && r0->singleton()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    // Equal pointer constants (klasses, nulls, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  // See if it is 2 unrelated classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  const TypeOopPtr* p0 = r0->isa_oopptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  const TypeOopPtr* p1 = r1->isa_oopptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  if (p0 && p1) {
206
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   819
    Node* in1 = in(1)->uncast();
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   820
    Node* in2 = in(2)->uncast();
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   821
    AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   822
    AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   823
    if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   824
      return TypeInt::CC_GT;  // different pointers
d61cf247afd5 6667580: Optimize CmpP for allocations
kvn
parents: 1
diff changeset
   825
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    ciKlass* klass0 = p0->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    bool    xklass0 = p0->klass_is_exact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    ciKlass* klass1 = p1->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    bool    xklass1 = p1->klass_is_exact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    if (klass0 && klass1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
        kps != 1 &&             // both or neither are klass pointers
2335
e1965d139bb7 6820510: assertion failure with unloaded class in subnode.cpp
never
parents: 1432
diff changeset
   833
        klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces
2870
52b70541d4d3 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 2335
diff changeset
   834
        klass1->is_loaded() && !klass1->is_interface() &&
52b70541d4d3 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 2335
diff changeset
   835
        (!klass0->is_obj_array_klass() ||
52b70541d4d3 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 2335
diff changeset
   836
         !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) &&
52b70541d4d3 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 2335
diff changeset
   837
        (!klass1->is_obj_array_klass() ||
52b70541d4d3 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 2335
diff changeset
   838
         !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   839
      bool unrelated_classes = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      // See if neither subclasses the other, or if the class on top
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   841
      // is precise.  In either of these cases, the compare is known
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   842
      // to fail if at least one of the pointers is provably not null.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13205
diff changeset
   843
      if (klass0->equals(klass1)) {  // if types are unequal but klasses are equal
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
        // Do nothing; we know nothing for imprecise types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      } else if (klass0->is_subtype_of(klass1)) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   846
        // If klass1's type is PRECISE, then classes are unrelated.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   847
        unrelated_classes = xklass1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      } else if (klass1->is_subtype_of(klass0)) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   849
        // If klass0's type is PRECISE, then classes are unrelated.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   850
        unrelated_classes = xklass0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
      } else {                  // Neither subtypes the other
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   852
        unrelated_classes = true;
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   853
      }
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   854
      if (unrelated_classes) {
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   855
        // The oops classes are known to be unrelated. If the joined PTRs of
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   856
        // two oops is not Null and not Bottom, then we are sure that one
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   857
        // of the two oops is non-null, and the comparison will always fail.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   858
        TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   859
        if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   860
          return TypeInt::CC_GT;
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
   861
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // Known constants can be compared exactly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  // Null can be distinguished from any NotNull pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // Unknown inputs makes an unknown result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  if( r0->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    intptr_t bits0 = r0->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
    if( r1->singleton() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
      return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  } else if( r1->singleton() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    intptr_t bits1 = r1->get_con();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   881
static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   882
  // Return the klass node for (indirect load from OopHandle)
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   883
  //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   884
  //   or NULL if not matching.
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   885
  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   886
  if (bs->is_gc_barrier_node(n)) {
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   887
    n = bs->step_over_gc_barrier(n);
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   888
  }
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 49816
diff changeset
   889
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   890
  if (n->Opcode() != Op_LoadP) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   891
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   892
  const TypeInstPtr* tp = phase->type(n)->isa_instptr();
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   893
  if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   894
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   895
  Node* adr = n->in(MemNode::Address);
49816
a3e79f97e86b 8200555: OopHandle should use Access API
coleenp
parents: 48089
diff changeset
   896
  // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
47580
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   897
  if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   898
  adr = adr->in(MemNode::Address);
96392e113a0a 8186777: Make Klass::_java_mirror an OopHandle
coleenp
parents: 47216
diff changeset
   899
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   900
  intptr_t off = 0;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   901
  Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   902
  if (k == NULL)  return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   903
  const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   904
  if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   905
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   906
  // We've found the klass node of a Java mirror load.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   907
  return k;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   908
}
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   909
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   910
static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   911
  // for ConP(Foo.class) return ConP(Foo.klass)
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   912
  // otherwise return NULL
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   913
  if (!n->is_Con()) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   914
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   915
  const TypeInstPtr* tp = phase->type(n)->isa_instptr();
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   916
  if (!tp) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   917
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   918
  ciType* mirror_type = tp->java_mirror_type();
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   919
  // TypeInstPtr::java_mirror_type() returns non-NULL for compile-
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   920
  // time Class constants only.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   921
  if (!mirror_type) return NULL;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   922
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   923
  // x.getClass() == int.class can never be true (for all primitive types)
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   924
  // Return a ConP(NULL) node for this case.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   925
  if (mirror_type->is_classless()) {
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   926
    return phase->makecon(TypePtr::NULL_PTR);
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   927
  }
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   928
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   929
  // return the ConP(Foo.klass)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13205
diff changeset
   930
  assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   931
  return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   932
}
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   933
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
//------------------------------Ideal------------------------------------------
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   935
// Normalize comparisons between Java mirror loads to compare the klass instead.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   936
//
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   937
// Also check for the case of comparing an unknown klass loaded from the primary
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
// super-type array vs a known klass with no subtypes.  This amounts to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
// checking to see an unknown klass subtypes a known klass with no subtypes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
// this only happens on an exact match.  We can shorten this test by 1 load.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
12945
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   942
  // Normalize comparisons between Java mirrors into comparisons of the low-
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   943
  // level klass, where a dependent load could be shortened.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   944
  //
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   945
  // The new pattern has a nice effect of matching the same pattern used in the
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   946
  // fast path of instanceof/checkcast/Class.isInstance(), which allows
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   947
  // redundant exact type check be optimized away by GVN.
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   948
  // For example, in
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   949
  //   if (x.getClass() == Foo.class) {
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   950
  //     Foo foo = (Foo) x;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   951
  //     // ... use a ...
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   952
  //   }
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   953
  // a CmpPNode could be shared between if_acmpne and checkcast
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   954
  {
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   955
    Node* k1 = isa_java_mirror_load(phase, in(1));
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   956
    Node* k2 = isa_java_mirror_load(phase, in(2));
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   957
    Node* conk2 = isa_const_java_mirror(phase, in(2));
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   958
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   959
    if (k1 && (k2 || conk2)) {
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   960
      Node* lhs = k1;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   961
      Node* rhs = (k2 != NULL) ? k2 : conk2;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   962
      this->set_req(1, lhs);
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   963
      this->set_req(2, rhs);
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   964
      return this;
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   965
    }
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   966
  }
e63d6176cbd1 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 12739
diff changeset
   967
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  // Constant pointer on right?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  if (t2 == NULL || !t2->klass_is_exact())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  // Get the constant klass we are comparing to.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  ciKlass* superklass = t2->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  // Now check for LoadKlass on left.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  Node* ldk1 = in(1);
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
   977
  if (ldk1->is_DecodeNKlass()) {
1055
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
   978
    ldk1 = ldk1->in(1);
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
   979
    if (ldk1->Opcode() != Op_LoadNKlass )
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
   980
      return NULL;
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
   981
  } else if (ldk1->Opcode() != Op_LoadKlass )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  // Take apart the address of the LoadKlass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  Node* adr1 = ldk1->in(MemNode::Address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  intptr_t con2 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  if (ldk2 == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  if (con2 == oopDesc::klass_offset_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    // We are inspecting an object's concrete class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    // Short-circuit the check if the query is abstract.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    if (superklass->is_interface() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
        superklass->is_abstract()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
      // Make it come out always false:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
      return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  // Check for a LoadKlass from primary supertype array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  // Any nested loadklass from loadklass+con must be from the p.s. array.
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
  1002
  if (ldk2->is_DecodeNKlass()) {
1055
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
  1003
    // Keep ldk2 as DecodeN since it could be used in CmpP below.
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
  1004
    if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
  1005
      return NULL;
f4fb9fb08038 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 781
diff changeset
  1006
  } else if (ldk2->Opcode() != Op_LoadKlass)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  // Verify that we understand the situation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  if (con2 != (intptr_t) superklass->super_check_offset())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
    return NULL;                // Might be element-klass loading from array klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  // If 'superklass' has no subklasses and is not an interface, then we are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  // assured that the only input which will pass the type check is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  // 'superklass' itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  // We could be more liberal here, and allow the optimization on interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  // which have a single implementor.  This would require us to increase the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  // expressiveness of the add_dependency() mechanism.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  // %%% Do this after we fix TypeOopPtr:  Deps are expressive enough now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  // Object arrays must have their base element have no subtypes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  while (superklass->is_obj_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    ciType* elem = superklass->as_obj_array_klass()->element_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    superklass = elem->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  if (superklass->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    ciInstanceKlass* ik = superklass->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
    if (ik->has_subklass() || ik->is_interface())  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // Add a dependency if there is a chance that a subclass will be added later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    if (!ik->is_final()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
      phase->C->dependencies()->assert_leaf_type(ik);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  // Bypass the dependent load, and compare directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  this->set_req(1,ldk2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  return this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
//=============================================================================
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1043
//------------------------------sub--------------------------------------------
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1044
// Simplify an CmpN (compare 2 pointers) node, based on local information.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1045
// If both inputs are constants, compare them.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1046
const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
767
64fb1fd7186d 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 758
diff changeset
  1047
  const TypePtr *r0 = t1->make_ptr(); // Handy access
64fb1fd7186d 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 758
diff changeset
  1048
  const TypePtr *r1 = t2->make_ptr();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1049
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1050
  // Undefined inputs makes for an undefined result
17384
4e6ea5fa04ad 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 16670
diff changeset
  1051
  if ((r0 == NULL) || (r1 == NULL) ||
4e6ea5fa04ad 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 16670
diff changeset
  1052
      TypePtr::above_centerline(r0->_ptr) ||
4e6ea5fa04ad 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 16670
diff changeset
  1053
      TypePtr::above_centerline(r1->_ptr)) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1054
    return Type::TOP;
17384
4e6ea5fa04ad 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 16670
diff changeset
  1055
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1056
  if (r0 == r1 && r0->singleton()) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1057
    // Equal pointer constants (klasses, nulls, etc.)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1058
    return TypeInt::CC_EQ;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1059
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1060
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1061
  // See if it is 2 unrelated classes.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1062
  const TypeOopPtr* p0 = r0->isa_oopptr();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1063
  const TypeOopPtr* p1 = r1->isa_oopptr();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1064
  if (p0 && p1) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1065
    ciKlass* klass0 = p0->klass();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1066
    bool    xklass0 = p0->klass_is_exact();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1067
    ciKlass* klass1 = p1->klass();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1068
    bool    xklass1 = p1->klass_is_exact();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1069
    int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1070
    if (klass0 && klass1 &&
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1071
        kps != 1 &&             // both or neither are klass pointers
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1072
        !klass0->is_interface() && // do not trust interfaces
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1073
        !klass1->is_interface()) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1074
      bool unrelated_classes = false;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1075
      // See if neither subclasses the other, or if the class on top
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1076
      // is precise.  In either of these cases, the compare is known
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1077
      // to fail if at least one of the pointers is provably not null.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13205
diff changeset
  1078
      if (klass0->equals(klass1)) { // if types are unequal but klasses are equal
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1079
        // Do nothing; we know nothing for imprecise types
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1080
      } else if (klass0->is_subtype_of(klass1)) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1081
        // If klass1's type is PRECISE, then classes are unrelated.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1082
        unrelated_classes = xklass1;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1083
      } else if (klass1->is_subtype_of(klass0)) {
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1084
        // If klass0's type is PRECISE, then classes are unrelated.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1085
        unrelated_classes = xklass0;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1086
      } else {                  // Neither subtypes the other
1058
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1087
        unrelated_classes = true;
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1088
      }
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1089
      if (unrelated_classes) {
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1090
        // The oops classes are known to be unrelated. If the joined PTRs of
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1091
        // two oops is not Null and not Bottom, then we are sure that one
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1092
        // of the two oops is non-null, and the comparison will always fail.
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1093
        TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1094
        if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1095
          return TypeInt::CC_GT;
52be2dbbdc79 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 1055
diff changeset
  1096
        }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1097
      }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1098
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1099
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1100
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1101
  // Known constants can be compared exactly
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1102
  // Null can be distinguished from any NotNull pointers
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1103
  // Unknown inputs makes an unknown result
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1104
  if( r0->singleton() ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1105
    intptr_t bits0 = r0->get_con();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1106
    if( r1->singleton() )
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1107
      return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1108
    return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1109
  } else if( r1->singleton() ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1110
    intptr_t bits1 = r1->get_con();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1111
    return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1112
  } else
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1113
    return TypeInt::CC;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1114
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1115
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1116
//------------------------------Ideal------------------------------------------
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1117
Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1118
  return NULL;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1119
}
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1120
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 206
diff changeset
  1121
//=============================================================================
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
// Simplify an CmpF (compare 2 floats ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
// If both inputs are constants, compare them.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
  1125
const Type* CmpFNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  // Not constants?  Don't know squat - even if they are the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  // value!  If they are NaN's they compare to LT instead of EQ.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  const TypeF *tf1 = t1->isa_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  const TypeF *tf2 = t2->isa_float_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
  if( !tf1 || !tf2 ) return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  // This implements the Java bytecode fcmpl, so unordered returns -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  if( tf1->is_nan() || tf2->is_nan() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
  if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
// Simplify an CmpD (compare 2 doubles ) node, based on local information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
// If both inputs are constants, compare them.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
  1155
const Type* CmpDNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
  const Node* in1 = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  const Node* in2 = in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  // Either input is TOP ==> the result is TOP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
  const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  if( t2 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
  // Not constants?  Don't know squat - even if they are the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  // value!  If they are NaN's they compare to LT instead of EQ.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  const TypeD *td1 = t1->isa_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
  const TypeD *td2 = t2->isa_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  if( !td1 || !td2 ) return TypeInt::CC;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
  // This implements the Java bytecode dcmpl, so unordered returns -1.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  if( td1->is_nan() || td2->is_nan() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  if( td1->_d < td2->_d ) return TypeInt::CC_LT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
  if( td1->_d > td2->_d ) return TypeInt::CC_GT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  assert( td1->_d == td2->_d, "do not understand FP behavior" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  return TypeInt::CC_EQ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  // Check if we can change this to a CmpF and remove a ConvD2F operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
  // Change  (CMPD (F2D (float)) (ConD value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  // To      (CMPF      (float)  (ConF value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
  // Valid when 'value' does not lose precision as a float.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
  // Benefits: eliminates conversion, does not require 24-bit mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  // NaNs prevent commuting operands.  This transform works regardless of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  // order of ConD and ConvF2D inputs by preserving the original order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
  int idx_f2d = 1;              // ConvF2D on left side?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  if( in(idx_f2d)->Opcode() != Op_ConvF2D )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
    idx_f2d = 2;                // No, swap to check for reversed args
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  int idx_con = 3-idx_f2d;      // Check for the constant on other input
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  if( ConvertCmpD2CmpF &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
      in(idx_f2d)->Opcode() == Op_ConvF2D &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
      in(idx_con)->Opcode() == Op_ConD ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
    const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
    double t2_value_as_double = t2->_d;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    float  t2_value_as_float  = (float)t2_value_as_double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    if( t2_value_as_double == (double)t2_value_as_float ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
      // Test value can be represented as a float
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
      // Eliminate the conversion to double and create new comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
      Node *new_in1 = in(idx_f2d)->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
      Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
      if( idx_f2d != 1 ) {      // Must flip args to match original order
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
        Node *tmp = new_in1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
        new_in1 = new_in2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
        new_in2 = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
      CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1212
        ? new CmpF3Node( new_in1, new_in2 )
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1213
        : new CmpFNode ( new_in1, new_in2 ) ;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
      return new_cmp;           // Changed to CmpFNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
    // Testing value required the precision of a double
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  return NULL;                  // No change
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
//------------------------------cc2logical-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
// Convert a condition code type to a logical type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
const Type *BoolTest::cc2logical( const Type *CC ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
  if( CC == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
  const TypeInt *ti = CC->is_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  if( ti->is_con() ) {          // Only 1 kind of condition codes set?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
    // Match low order 2 bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
    if( _test & 4 ) tmp = 1-tmp;     // Optionally complement result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    return TypeInt::make(tmp);       // Boolean result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  if( CC == TypeInt::CC_GE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    if( _test == ge ) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
    if( _test == lt ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  if( CC == TypeInt::CC_LE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
    if( _test == le ) return TypeInt::ONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
    if( _test == gt ) return TypeInt::ZERO;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  return TypeInt::BOOL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
//------------------------------dump_spec-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
// Print special per-node info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
void BoolTest::dump_on(outputStream *st) const {
20289
35d78de0c547 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 17384
diff changeset
  1251
  const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"};
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23528
diff changeset
  1252
  st->print("%s", msg[_test]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
uint BoolNode::size_of() const { return sizeof(BoolNode); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
//------------------------------operator==-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
uint BoolNode::cmp( const Node &n ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
  const BoolNode *b = (const BoolNode *)&n; // Cast up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
  return (_test._test == b->_test._test);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
//-------------------------------make_predicate--------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  if (test_value->is_Con())   return test_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  if (test_value->is_Bool())  return test_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
  if (test_value->is_CMove() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
      test_value->in(CMoveNode::Condition)->is_Bool()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    BoolNode*   bol   = test_value->in(CMoveNode::Condition)->as_Bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
      return bol;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
    } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
      return phase->transform( bol->negate(phase) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
    // Else fall through.  The CMove gets in the way of the test.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
    // It should be the case that make_predicate(bol->as_int_value()) == bol.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
  }
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1282
  Node* cmp = new CmpINode(test_value, phase->intcon(0));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
  cmp = phase->transform(cmp);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1284
  Node* bol = new BoolNode(cmp, BoolTest::ne);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  return phase->transform(bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
//--------------------------------as_int_value---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
Node* BoolNode::as_int_value(PhaseGVN* phase) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  // Inverse to make_predicate.  The CMove probably boils down to a Conv2B.
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1291
  Node* cmov = CMoveNode::make(NULL, this,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
                               phase->intcon(0), phase->intcon(1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
                               TypeInt::BOOL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
  return phase->transform(cmov);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
//----------------------------------negate-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
BoolNode* BoolNode::negate(PhaseGVN* phase) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1299
  return new BoolNode(in(1), _test.negate());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
26165
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1302
// Change "bool eq/ne (cmp (add/sub A B) C)" into false/true if add/sub
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1303
// overflows and we can prove that C is not in the two resulting ranges.
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1304
// This optimization is similar to the one performed by CmpUNode::Value().
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1305
Node* BoolNode::fold_cmpI(PhaseGVN* phase, SubNode* cmp, Node* cmp1, int cmp_op,
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1306
                          int cmp1_op, const TypeInt* cmp2_type) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1307
  // Only optimize eq/ne integer comparison of add/sub
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1308
  if((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1309
     (cmp_op == Op_CmpI) && (cmp1_op == Op_AddI || cmp1_op == Op_SubI)) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1310
    // Skip cases were inputs of add/sub are not integers or of bottom type
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1311
    const TypeInt* r0 = phase->type(cmp1->in(1))->isa_int();
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1312
    const TypeInt* r1 = phase->type(cmp1->in(2))->isa_int();
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1313
    if ((r0 != NULL) && (r0 != TypeInt::INT) &&
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1314
        (r1 != NULL) && (r1 != TypeInt::INT) &&
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1315
        (cmp2_type != TypeInt::INT)) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1316
      // Compute exact (long) type range of add/sub result
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1317
      jlong lo_long = r0->_lo;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1318
      jlong hi_long = r0->_hi;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1319
      if (cmp1_op == Op_AddI) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1320
        lo_long += r1->_lo;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1321
        hi_long += r1->_hi;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1322
      } else {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1323
        lo_long -= r1->_hi;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1324
        hi_long -= r1->_lo;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1325
      }
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1326
      // Check for over-/underflow by casting to integer
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1327
      int lo_int = (int)lo_long;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1328
      int hi_int = (int)hi_long;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1329
      bool underflow = lo_long != (jlong)lo_int;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1330
      bool overflow  = hi_long != (jlong)hi_int;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1331
      if ((underflow != overflow) && (hi_int < lo_int)) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1332
        // Overflow on one boundary, compute resulting type ranges:
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1333
        // tr1 [MIN_INT, hi_int] and tr2 [lo_int, MAX_INT]
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1334
        int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1335
        const TypeInt* tr1 = TypeInt::make(min_jint, hi_int, w);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1336
        const TypeInt* tr2 = TypeInt::make(lo_int, max_jint, w);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1337
        // Compare second input of cmp to both type ranges
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1338
        const Type* sub_tr1 = cmp->sub(tr1, cmp2_type);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1339
        const Type* sub_tr2 = cmp->sub(tr2, cmp2_type);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1340
        if (sub_tr1 == TypeInt::CC_LT && sub_tr2 == TypeInt::CC_GT) {
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1341
          // The result of the add/sub will never equal cmp2. Replace BoolNode
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1342
          // by false (0) if it tests for equality and by true (1) otherwise.
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1343
          return ConINode::make((_test._test == BoolTest::eq) ? 0 : 1);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1344
        }
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1345
      }
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1346
    }
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1347
  }
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1348
  return NULL;
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1349
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1351
static bool is_counted_loop_cmp(Node *cmp) {
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1352
  Node *n = cmp->in(1)->in(1);
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1353
  return n != NULL &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1354
         n->is_Phi() &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1355
         n->in(0) != NULL &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1356
         n->in(0)->is_CountedLoop() &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1357
         n->in(0)->as_CountedLoop()->phi() == n;
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1358
}
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1359
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
//------------------------------Ideal------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  // This moves the constant to the right.  Helps value-numbering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  Node *cmp = in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  if( !cmp->is_Sub() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  int cop = cmp->Opcode();
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 22234
diff changeset
  1367
  if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  Node *cmp1 = cmp->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  Node *cmp2 = cmp->in(2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  if( !cmp1 ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
22911
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 22234
diff changeset
  1372
  if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) {
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 22234
diff changeset
  1373
    return NULL;
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 22234
diff changeset
  1374
  }
ff49c48c887d 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 22234
diff changeset
  1375
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
  // Constant on left?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
  Node *con = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
  uint op2 = cmp2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
  // Move constants to the right of compare's to canonicalize.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
  // Do not muck with Opaque1 nodes, as this indicates a loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
  // guard that cannot change shape.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
  if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
      // Because of NaN's, CmpD and CmpF are not commutative
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
      cop != Op_CmpD && cop != Op_CmpF &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
      // Protect against swapping inputs to a compare when it is used by a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
      // counted loop exit, which requires maintaining the loop-limit as in(2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
      !is_counted_loop_exit_test() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
    // Ok, commute the constant to the right of the cmp node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    // Clone the Node, getting a new Node of the same class
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
    cmp = cmp->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    // Swap inputs to the clone
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    cmp->swap_edges(1, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
    cmp = phase->transform( cmp );
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1394
    return new BoolNode( cmp, _test.commute() );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  // The XOR-1 is an idiom used to flip the sense of a bool.  We flip the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
  // test instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
  int cmp1_op = cmp1->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
  const TypeInt* cmp2_type = phase->type(cmp2)->isa_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
  if (cmp2_type == NULL)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  Node* j_xor = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  if( cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
      cmp1_op == Op_XorI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
      j_xor->in(1) != j_xor &&          // An xor of itself is dead
9966
b30a5eb9bcff 6956668: misbehavior of XOR operator (^) with int
kvn
parents: 9439
diff changeset
  1407
      phase->type( j_xor->in(1) ) == TypeInt::BOOL &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
      phase->type( j_xor->in(2) ) == TypeInt::ONE &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
      (_test._test == BoolTest::eq ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
       _test._test == BoolTest::ne) ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1411
    Node *ncmp = phase->transform(new CmpINode(j_xor->in(1),cmp2));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1412
    return new BoolNode( ncmp, _test.negate() );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1415
  // Change ((x & m) u<= m) or ((m & x) u<= m) to always true
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1416
  // Same with ((x & m) u< m+1) and ((m & x) u< m+1)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1417
  if (cop == Op_CmpU &&
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1418
      cmp1_op == Op_AndI) {
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1419
    Node* bound = NULL;
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1420
    if (_test._test == BoolTest::le) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1421
      bound = cmp2;
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1422
    } else if (_test._test == BoolTest::lt &&
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1423
               cmp2->Opcode() == Op_AddI &&
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1424
               cmp2->in(2)->find_int_con(0) == 1) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1425
      bound = cmp2->in(1);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1426
    }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1427
    if (cmp1->in(2) == bound || cmp1->in(1) == bound) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1428
      return ConINode::make(1);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1429
    }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1430
  }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1431
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1432
  // Change ((x & (m - 1)) u< m) into (m > 0)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1433
  // This is the off-by-one variant of the above
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1434
  if (cop == Op_CmpU &&
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1435
      _test._test == BoolTest::lt &&
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1436
      cmp1_op == Op_AndI) {
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1437
    Node* l = cmp1->in(1);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1438
    Node* r = cmp1->in(2);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1439
    for (int repeat = 0; repeat < 2; repeat++) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1440
      bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 &&
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1441
                   r->in(1) == cmp2;
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1442
      if (match) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1443
        // arraylength known to be non-negative, so a (arraylength != 0) is sufficient,
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1444
        // but to be compatible with the array range check pattern, use (arraylength u> 0)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1445
        Node* ncmp = cmp2->Opcode() == Op_LoadRange
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1446
                     ? phase->transform(new CmpUNode(cmp2, phase->intcon(0)))
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1447
                     : phase->transform(new CmpINode(cmp2, phase->intcon(0)));
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1448
        return new BoolNode(ncmp, BoolTest::gt);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1449
      } else {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1450
        // commute and try again
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1451
        l = cmp1->in(2);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1452
        r = cmp1->in(1);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1453
      }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1454
    }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1455
  }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1456
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1457
  // Change x u< 1 or x u<= 0 to x == 0
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1458
  if (cop == Op_CmpU &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1459
      cmp1_op != Op_LoadRange &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1460
      ((_test._test == BoolTest::lt &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1461
        cmp2->find_int_con(-1) == 1) ||
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1462
       (_test._test == BoolTest::le &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1463
        cmp2->find_int_con(-1) == 0))) {
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1464
    Node* ncmp = phase->transform(new CmpINode(cmp1, phase->intcon(0)));
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1465
    return new BoolNode(ncmp, BoolTest::eq);
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1466
  }
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1467
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1468
  // Change (arraylength <= 0) or (arraylength == 0)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1469
  //   into (arraylength u<= 0)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1470
  // Also change (arraylength != 0) into (arraylength u> 0)
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1471
  // The latter version matches the code pattern generated for
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1472
  // array range checks, which will more likely be optimized later.
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1473
  if (cop == Op_CmpI &&
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1474
      cmp1_op == Op_LoadRange &&
35756
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1475
      cmp2->find_int_con(-1) == 0) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1476
    if (_test._test == BoolTest::le || _test._test == BoolTest::eq) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1477
      Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2));
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1478
      return new BoolNode(ncmp, BoolTest::le);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1479
    } else if (_test._test == BoolTest::ne) {
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1480
      Node* ncmp = phase->transform(new CmpUNode(cmp1, cmp2));
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1481
      return new BoolNode(ncmp, BoolTest::gt);
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1482
    }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1483
  }
28e2a0fd6756 8003585: strength reduce or eliminate range checks for power-of-two sized arrays
kmo
parents: 35551
diff changeset
  1484
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
  // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)".
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  // This is a standard idiom for branching on a boolean value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
  Node *c2b = cmp1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
  if( cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
      cmp1_op == Op_Conv2B &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
      (_test._test == BoolTest::eq ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
       _test._test == BoolTest::ne) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
    Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int()
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1493
       ? (Node*)new CmpINode(c2b->in(1),cmp2)
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1494
       : (Node*)new CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR))
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
    );
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1496
    return new BoolNode( ncmp, _test._test );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
  // Comparing a SubI against a zero is equal to comparing the SubI
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
  // arguments directly.  This only works for eq and ne comparisons
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
  // due to possible integer overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
  if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
        (cop == Op_CmpI) &&
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1504
        (cmp1_op == Op_SubI) &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
        ( cmp2_type == TypeInt::ZERO ) ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1506
    Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),cmp1->in(2)));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1507
    return new BoolNode( ncmp, _test._test );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1510
  // Same as above but with and AddI of a constant
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1511
  if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1512
      cop == Op_CmpI &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1513
      cmp1_op == Op_AddI &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1514
      cmp1->in(2) != NULL &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1515
      phase->type(cmp1->in(2))->isa_int() &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1516
      phase->type(cmp1->in(2))->is_int()->is_con() &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1517
      cmp2_type == TypeInt::ZERO &&
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1518
      !is_counted_loop_cmp(cmp) // modifying the exit test of a counted loop messes the counted loop shape
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1519
      ) {
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1520
    const TypeInt* cmp1_in2 = phase->type(cmp1->in(2))->is_int();
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1521
    Node *ncmp = phase->transform( new CmpINode(cmp1->in(1),phase->intcon(-cmp1_in2->_hi)));
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1522
    return new BoolNode( ncmp, _test._test );
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1523
  }
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1524
51863
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1525
  // Change "bool eq/ne (cmp (phi (X -X) 0))" into "bool eq/ne (cmp X 0)"
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1526
  // since zero check of conditional negation of an integer is equal to
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1527
  // zero check of the integer directly.
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1528
  if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1529
      (cop == Op_CmpI) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1530
      (cmp2_type == TypeInt::ZERO) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1531
      (cmp1_op == Op_Phi)) {
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1532
    // There should be a diamond phi with true path at index 1 or 2
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1533
    PhiNode *phi = cmp1->as_Phi();
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1534
    int idx_true = phi->is_diamond_phi();
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1535
    if (idx_true != 0) {
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1536
      // True input is in(idx_true) while false input is in(3 - idx_true)
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1537
      Node *tin = phi->in(idx_true);
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1538
      Node *fin = phi->in(3 - idx_true);
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1539
      if ((tin->Opcode() == Op_SubI) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1540
          (phase->type(tin->in(1)) == TypeInt::ZERO) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1541
          (tin->in(2) == fin)) {
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1542
        // Found conditional negation at true path, create a new CmpINode without that
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1543
        Node *ncmp = phase->transform(new CmpINode(fin, cmp2));
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1544
        return new BoolNode(ncmp, _test._test);
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1545
      }
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1546
      if ((fin->Opcode() == Op_SubI) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1547
          (phase->type(fin->in(1)) == TypeInt::ZERO) &&
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1548
          (fin->in(2) == tin)) {
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1549
        // Found conditional negation at false path, create a new CmpINode without that
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1550
        Node *ncmp = phase->transform(new CmpINode(tin, cmp2));
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1551
        return new BoolNode(ncmp, _test._test);
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1552
      }
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1553
    }
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1554
  }
bc38c75eed57 8210152: Optimize integer divisible by power-of-2 check
thartmann
parents: 51666
diff changeset
  1555
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  // Change (-A vs 0) into (A vs 0) by commuting the test.  Disallow in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
  // most general case because negating 0x80000000 does nothing.  Needed for
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  // the CmpF3/SubI/CmpI idiom.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  if( cop == Op_CmpI &&
51666
7e6b86eb7914 8209544: AES encrypt performance regression in jdk11b11
roland
parents: 51485
diff changeset
  1560
      cmp1_op == Op_SubI &&
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
      cmp2_type == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
      phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1564
    Node *ncmp = phase->transform( new CmpINode(cmp1->in(2),cmp2));
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 24482
diff changeset
  1565
    return new BoolNode( ncmp, _test.commute() );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
26165
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1568
  // Try to optimize signed integer comparison
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1569
  return fold_cmpI(phase, cmp->as_Sub(), cmp1, cop, cmp1_op, cmp2_type);
1b175b39dfc1 8043284: Optimize signed integer comparison
thartmann
parents: 25930
diff changeset
  1570
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  //  The transformation below is not valid for either signed or unsigned
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  //  comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  //  This transformation can be resurrected when we are able to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
  //  make inferences about the range of values being subtracted from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  //  (or added to) relative to the wraparound point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
  //    // Remove +/-1's if possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  //    // "X <= Y-1" becomes "X <  Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
  //    // "X+1 <= Y" becomes "X <  Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
  //    // "X <  Y+1" becomes "X <= Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
  //    // "X-1 <  Y" becomes "X <= Y"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
  //    // Do not this to compares off of the counted-loop-end.  These guys are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  //    // checking the trip counter and they want to use the post-incremented
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
  //    // counter.  If they use the PRE-incremented counter, then the counter has
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
  //    // to be incremented in a private block on a loop backedge.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
  //    if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  //      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
  //  #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  //    // Do not do this in a wash GVN pass during verification.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
  //    // Gets triggered by too many simple optimizations to be bothered with
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
  //    // re-trying it again and again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
  //    if( !phase->allow_progress() ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  //  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
  //    // Not valid for unsigned compare because of corner cases in involving zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  //    // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
  //    // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
  //    // "0 <=u Y" is always true).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  //    if( cmp->Opcode() == Op_CmpU ) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
  //    int cmp2_op = cmp2->Opcode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  //    if( _test._test == BoolTest::le ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
  //      if( cmp1_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  //          phase->type( cmp1->in(2) ) == TypeInt::ONE )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
  //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
  //      else if( cmp2_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  //         phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
  //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
  //    } else if( _test._test == BoolTest::lt ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  //      if( cmp1_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
  //          phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  //        return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
  //      else if( cmp2_op == Op_AddI &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
  //         phase->type( cmp2->in(2) ) == TypeInt::ONE )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
  //        return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
  //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
// Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
// based on local information.   If the input is constant, do it.
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
  1620
const Type* BoolNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
  return _test.cc2logical( phase->type( in(1) ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1624
#ifndef PRODUCT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
//------------------------------dump_spec--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
// Dump special per-node info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
void BoolNode::dump_spec(outputStream *st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
  st->print("[");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
  _test.dump_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
  st->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
}
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1632
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1633
//-------------------------------related---------------------------------------
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1634
// A BoolNode's related nodes are all of its data inputs, and all of its
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1635
// outputs until control nodes are hit, which are included. In compact
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1636
// representation, inputs till level 3 and immediate outputs are included.
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1637
void BoolNode::related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1638
  if (compact) {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1639
    this->collect_nodes(in_rel, 3, false, true);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1640
    this->collect_nodes(out_rel, -1, false, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1641
  } else {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1642
    this->collect_nodes_in_all_data(in_rel, false);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1643
    this->collect_nodes_out_all_ctrl_boundary(out_rel);
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1644
  }
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1645
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 27708
diff changeset
  1648
//----------------------is_counted_loop_exit_test------------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
// Returns true if node is used by a counted loop node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
bool BoolNode::is_counted_loop_exit_test() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
    Node* use = fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
    if (use->is_CountedLoopEnd()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
// Compute sqrt
35551
36ef3841fb34 8146629: Make phase->is_IterGVN() accessible from Node::Identity and Node::Value
thartmann
parents: 35540
diff changeset
  1663
const Type* SqrtDNode::Value(PhaseGVN* phase) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  const Type *t1 = phase->type( in(1) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
  if( t1 == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
  double d = t1->getd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
  if( d < 0.0 ) return Type::DOUBLE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
  return TypeD::make( sqrt( d ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
}
48089
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1671
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1672
const Type* SqrtFNode::Value(PhaseGVN* phase) const {
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1673
  const Type *t1 = phase->type( in(1) );
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1674
  if( t1 == Type::TOP ) return Type::TOP;
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1675
  if( t1->base() != Type::FloatCon ) return Type::FLOAT;
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1676
  float f = t1->getf();
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1677
  if( f < 0.0f ) return Type::FLOAT;
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1678
  return TypeF::make( (float)sqrt( (double)f ) );
22c9856fc2c2 8190800: Support vectorization of Math.sqrt() on floats
rlupusoru
parents: 47580
diff changeset
  1679
}