annotate src/share/vm/opto/subnode.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 5b8e0f84f00f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14495
diff changeset
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1174
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1174
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1174
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "compiler/compileLog.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "opto/addnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "opto/callnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "opto/cfgnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "opto/connode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "opto/loopnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "opto/matcher.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #include "opto/mulnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 #include "opto/opcodes.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #include "opto/phaseX.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #include "opto/subnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 #include "runtime/sharedRuntime.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Portions of code courtesy of Clifford Click
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Optimization - Graph Style
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #include "math.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
47 //------------------------------Identity---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // If right input is a constant 0, return the left input.
a61af66fc99e Initial load
duke
parents:
diff changeset
49 Node *SubNode::Identity( PhaseTransform *phase ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 assert(in(1) != this, "Must already have called Value");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 assert(in(2) != this, "Must already have called Value");
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Remove double negation
a61af66fc99e Initial load
duke
parents:
diff changeset
54 const Type *zero = add_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if( phase->type( in(1) )->higher_equal( zero ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
56 in(2)->Opcode() == Opcode() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
57 phase->type( in(2)->in(1) )->higher_equal( zero ) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return in(2)->in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
212
99bf1609e2a5 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 113
diff changeset
61 // Convert "(X+Y) - Y" into X and "(X+Y) - X" into Y
0
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if( in(1)->Opcode() == Op_AddI ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 if( phase->eqv(in(1)->in(2),in(2)) )
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return in(1)->in(1);
212
99bf1609e2a5 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 113
diff changeset
65 if (phase->eqv(in(1)->in(1),in(2)))
99bf1609e2a5 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 113
diff changeset
66 return in(1)->in(2);
99bf1609e2a5 6697236: missing Identity for "(X+Y) - X" into Y
never
parents: 113
diff changeset
67
0
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Also catch: "(X + Opaque2(Y)) - Y". In this case, 'Y' is a loop-varying
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // trip counter and X is likely to be loop-invariant (that's how O2 Nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // are originally used, although the optimizer sometimes jiggers things).
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // This folding through an O2 removes a loop-exit use of a loop-varying
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // value and generally lowers register pressure in and around the loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if( in(1)->in(2)->Opcode() == Op_Opaque2 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
74 phase->eqv(in(1)->in(2)->in(1),in(2)) )
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return in(1)->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return ( phase->type( in(2) )->higher_equal( zero ) ) ? in(1) : this;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // A subtract node differences it's two inputs.
17936
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
83 const Type* SubNode::Value_common(PhaseTransform *phase) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 const Node* in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 const Node* in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Either input is TOP ==> the result is TOP
a61af66fc99e Initial load
duke
parents:
diff changeset
87 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if( t2 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Not correct for SubFnode and AddFNode (must check for infinity)
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Equal? Subtract is zero
4778
35acf8f0a2e4 7128352: assert(obj_node == obj) failed
kvn
parents: 3416
diff changeset
94 if (in1->eqv_uncast(in2)) return add_id();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Either input is BOTTOM ==> the result is the local BOTTOM
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if( t1 == Type::BOTTOM || t2 == Type::BOTTOM )
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return bottom_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
99
17936
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
100 return NULL;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
101 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
102
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
103 const Type* SubNode::Value(PhaseTransform *phase) const {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
104 const Type* t = Value_common(phase);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
105 if (t != NULL) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
106 return t;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
107 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
108 const Type* t1 = phase->type(in(1));
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
109 const Type* t2 = phase->type(in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return sub(t1,t2); // Local flavor of type subtraction
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 //------------------------------Helper function--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
117 static bool ok_to_convert(Node* inc, Node* iv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Do not collapse (x+c0)-y if "+" is a loop increment, because the
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // "-" is loop invariant and collapsing extends the live-range of "x"
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // to overlap with the "+", forcing another register to be used in
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // the loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // This test will be clearer with '&&' (apply DeMorgan's rule)
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // but I like the early cutouts that happen here.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 const PhiNode *phi;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if( ( !inc->in(1)->is_Phi() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
126 !(phi=inc->in(1)->as_Phi()) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
127 phi->is_copy() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
128 !phi->region()->is_CountedLoop() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
129 inc != phi->region()->as_CountedLoop()->incr() )
a61af66fc99e Initial load
duke
parents:
diff changeset
130 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Do not collapse (x+c0)-iv if "iv" is a loop induction variable,
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // because "x" maybe invariant.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ( !iv->is_loop_iv() )
a61af66fc99e Initial load
duke
parents:
diff changeset
134 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
141 Node *SubINode::Ideal(PhaseGVN *phase, bool can_reshape){
a61af66fc99e Initial load
duke
parents:
diff changeset
142 Node *in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Node *in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 uint op1 = in1->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 uint op2 = in2->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Check for dead loop
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
150 ( op1 == Op_AddI || op1 == Op_SubI ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
151 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
152 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(false, "dead loop in SubINode::Ideal");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 const Type *t2 = phase->type( in2 );
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if( t2 == Type::TOP ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Convert "x-c0" into "x+ -c0".
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if( t2->base() == Type::Int ){ // Might be bottom or top...
a61af66fc99e Initial load
duke
parents:
diff changeset
160 const TypeInt *i = t2->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if( i->is_con() )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
162 return new (phase->C) AddINode(in1, phase->intcon(-i->get_con()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // Convert "(x+c0) - y" into (x-y) + c0"
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Do not collapse (x+c0)-y if "+" is a loop increment or
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // if "y" is a loop induction variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if( op1 == Op_AddI && ok_to_convert(in1, in2) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 const Type *tadd = phase->type( in1->in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if( tadd->singleton() && tadd != Type::TOP ) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
171 Node *sub2 = phase->transform( new (phase->C) SubINode( in1->in(1), in2 ));
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
172 return new (phase->C) AddINode( sub2, in1->in(2) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // Convert "x - (y+c0)" into "(x-y) - c0"
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Need the same check as in above optimization but reversed.
a61af66fc99e Initial load
duke
parents:
diff changeset
179 if (op2 == Op_AddI && ok_to_convert(in2, in1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Node* in21 = in2->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 Node* in22 = in2->in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 const TypeInt* tcon = phase->type(in22)->isa_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (tcon != NULL && tcon->is_con()) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
184 Node* sub2 = phase->transform( new (phase->C) SubINode(in1, in21) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 Node* neg_c0 = phase->intcon(- tcon->get_con());
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
186 return new (phase->C) AddINode(sub2, neg_c0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 const Type *t1 = phase->type( in1 );
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if( t1 == Type::TOP ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // Check for dead loop
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if( ( op2 == Op_AddI || op2 == Op_SubI ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
196 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
197 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
198 assert(false, "dead loop in SubINode::Ideal");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // Convert "x - (x+y)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if( op2 == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
203 phase->eqv( in1, in2->in(1) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
204 return new (phase->C) SubINode( phase->intcon(0),in2->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Convert "(x-y) - x" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if( op1 == Op_SubI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
207 phase->eqv( in1->in(1), in2 ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
208 return new (phase->C) SubINode( phase->intcon(0),in1->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Convert "x - (y+x)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if( op2 == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
211 phase->eqv( in1, in2->in(2) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
212 return new (phase->C) SubINode( phase->intcon(0),in2->in(1));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Convert "0 - (x-y)" into "y-x"
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if( t1 == TypeInt::ZERO && op2 == Op_SubI )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
216 return new (phase->C) SubINode( in2->in(2), in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Convert "0 - (x+con)" into "-con-x"
a61af66fc99e Initial load
duke
parents:
diff changeset
219 jint con;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 if( t1 == TypeInt::ZERO && op2 == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
221 (con = in2->in(2)->find_int_con(0)) != 0 )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
222 return new (phase->C) SubINode( phase->intcon(-con), in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // Convert "(X+A) - (X+B)" into "A - B"
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(1) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
226 return new (phase->C) SubINode( in1->in(2), in2->in(2) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // Convert "(A+X) - (B+X)" into "A - B"
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(2) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
230 return new (phase->C) SubINode( in1->in(1), in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
231
400
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
232 // Convert "(A+X) - (X+B)" into "A - B"
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
233 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(2) == in2->in(1) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
234 return new (phase->C) SubINode( in1->in(1), in2->in(2) );
400
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
235
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
236 // Convert "(X+A) - (B+X)" into "A - B"
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
237 if( op1 == Op_AddI && op2 == Op_AddI && in1->in(1) == in2->in(2) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
238 return new (phase->C) SubINode( in1->in(2), in2->in(1) );
400
cc80376deb0c 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 296
diff changeset
239
0
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // Convert "A-(B-C)" into (A+C)-B", since add is commutative and generally
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // nicer to optimize than subtract.
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if( op2 == Op_SubI && in2->outcnt() == 1) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
243 Node *add1 = phase->transform( new (phase->C) AddINode( in1, in2->in(2) ) );
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
244 return new (phase->C) SubINode( add1, in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 //------------------------------sub--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // A subtract node differences it's two inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
252 const Type *SubINode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 const TypeInt *r0 = t1->is_int(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
254 const TypeInt *r1 = t2->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 int32 lo = r0->_lo - r1->_hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 int32 hi = r0->_hi - r1->_lo;
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // We next check for 32-bit overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // If that happens, we just assume all integers are possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
a61af66fc99e Initial load
duke
parents:
diff changeset
261 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
a61af66fc99e Initial load
duke
parents:
diff changeset
262 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
a61af66fc99e Initial load
duke
parents:
diff changeset
263 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return TypeInt::make(lo,hi,MAX2(r0->_widen,r1->_widen));
a61af66fc99e Initial load
duke
parents:
diff changeset
265 else // Overflow; assume all integers
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return TypeInt::INT;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
270 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
271 Node *SubLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 Node *in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Node *in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 uint op1 = in1->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 uint op2 = in2->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Check for dead loop
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if( phase->eqv( in1, this ) || phase->eqv( in2, this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
280 ( op1 == Op_AddL || op1 == Op_SubL ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
281 ( phase->eqv( in1->in(1), this ) || phase->eqv( in1->in(2), this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
282 phase->eqv( in1->in(1), in1 ) || phase->eqv( in1->in(2), in1 ) ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
283 assert(false, "dead loop in SubLNode::Ideal");
a61af66fc99e Initial load
duke
parents:
diff changeset
284 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 if( phase->type( in2 ) == Type::TOP ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 const TypeLong *i = phase->type( in2 )->isa_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // Convert "x-c0" into "x+ -c0".
a61af66fc99e Initial load
duke
parents:
diff changeset
289 if( i && // Might be bottom or top...
a61af66fc99e Initial load
duke
parents:
diff changeset
290 i->is_con() )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
291 return new (phase->C) AddLNode(in1, phase->longcon(-i->get_con()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // Convert "(x+c0) - y" into (x-y) + c0"
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Do not collapse (x+c0)-y if "+" is a loop increment or
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // if "y" is a loop induction variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if( op1 == Op_AddL && ok_to_convert(in1, in2) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 Node *in11 = in1->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
298 const Type *tadd = phase->type( in1->in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
299 if( tadd->singleton() && tadd != Type::TOP ) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
300 Node *sub2 = phase->transform( new (phase->C) SubLNode( in11, in2 ));
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
301 return new (phase->C) AddLNode( sub2, in1->in(2) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Convert "x - (y+c0)" into "(x-y) - c0"
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // Need the same check as in above optimization but reversed.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (op2 == Op_AddL && ok_to_convert(in2, in1)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 Node* in21 = in2->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 Node* in22 = in2->in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 const TypeLong* tcon = phase->type(in22)->isa_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (tcon != NULL && tcon->is_con()) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
312 Node* sub2 = phase->transform( new (phase->C) SubLNode(in1, in21) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
313 Node* neg_c0 = phase->longcon(- tcon->get_con());
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
314 return new (phase->C) AddLNode(sub2, neg_c0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 const Type *t1 = phase->type( in1 );
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if( t1 == Type::TOP ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
320
a61af66fc99e Initial load
duke
parents:
diff changeset
321 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // Check for dead loop
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if( ( op2 == Op_AddL || op2 == Op_SubL ) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
324 ( phase->eqv( in2->in(1), this ) || phase->eqv( in2->in(2), this ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
325 phase->eqv( in2->in(1), in2 ) || phase->eqv( in2->in(2), in2 ) ) )
a61af66fc99e Initial load
duke
parents:
diff changeset
326 assert(false, "dead loop in SubLNode::Ideal");
a61af66fc99e Initial load
duke
parents:
diff changeset
327 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
328
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // Convert "x - (x+y)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
330 if( op2 == Op_AddL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
331 phase->eqv( in1, in2->in(1) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
332 return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO), in2->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
333 // Convert "x - (y+x)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if( op2 == Op_AddL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
335 phase->eqv( in1, in2->in(2) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
336 return new (phase->C) SubLNode( phase->makecon(TypeLong::ZERO),in2->in(1));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // Convert "0 - (x-y)" into "y-x"
a61af66fc99e Initial load
duke
parents:
diff changeset
339 if( phase->type( in1 ) == TypeLong::ZERO && op2 == Op_SubL )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
340 return new (phase->C) SubLNode( in2->in(2), in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // Convert "(X+A) - (X+B)" into "A - B"
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(1) == in2->in(1) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
344 return new (phase->C) SubLNode( in1->in(2), in2->in(2) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // Convert "(A+X) - (B+X)" into "A - B"
a61af66fc99e Initial load
duke
parents:
diff changeset
347 if( op1 == Op_AddL && op2 == Op_AddL && in1->in(2) == in2->in(2) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
348 return new (phase->C) SubLNode( in1->in(1), in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
349
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // Convert "A-(B-C)" into (A+C)-B"
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if( op2 == Op_SubL && in2->outcnt() == 1) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
352 Node *add1 = phase->transform( new (phase->C) AddLNode( in1, in2->in(2) ) );
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
353 return new (phase->C) SubLNode( add1, in2->in(1) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 //------------------------------sub--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // A subtract node differences it's two inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
361 const Type *SubLNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 const TypeLong *r0 = t1->is_long(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
363 const TypeLong *r1 = t2->is_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 jlong lo = r0->_lo - r1->_hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 jlong hi = r0->_hi - r1->_lo;
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // We next check for 32-bit overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // If that happens, we just assume all integers are possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if( (((r0->_lo ^ r1->_hi) >= 0) || // lo ends have same signs OR
a61af66fc99e Initial load
duke
parents:
diff changeset
370 ((r0->_lo ^ lo) >= 0)) && // lo results have same signs AND
a61af66fc99e Initial load
duke
parents:
diff changeset
371 (((r0->_hi ^ r1->_lo) >= 0) || // hi ends have same signs OR
a61af66fc99e Initial load
duke
parents:
diff changeset
372 ((r0->_hi ^ hi) >= 0)) ) // hi results have same signs
a61af66fc99e Initial load
duke
parents:
diff changeset
373 return TypeLong::make(lo,hi,MAX2(r0->_widen,r1->_widen));
a61af66fc99e Initial load
duke
parents:
diff changeset
374 else // Overflow; assume all integers
a61af66fc99e Initial load
duke
parents:
diff changeset
375 return TypeLong::LONG;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
377
a61af66fc99e Initial load
duke
parents:
diff changeset
378 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
379 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // A subtract node differences its two inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
381 const Type *SubFPNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 const Node* in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 const Node* in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 // Either input is TOP ==> the result is TOP
a61af66fc99e Initial load
duke
parents:
diff changeset
385 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
387 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 if( t2 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
389
a61af66fc99e Initial load
duke
parents:
diff changeset
390 // if both operands are infinity of same sign, the result is NaN; do
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // not replace with zero
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if( (t1->is_finite() && t2->is_finite()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 if( phase->eqv(in1, in2) ) return add_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Either input is BOTTOM ==> the result is the local BOTTOM
a61af66fc99e Initial load
duke
parents:
diff changeset
397 const Type *bot = bottom_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
398 if( (t1 == bot) || (t2 == bot) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
399 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
a61af66fc99e Initial load
duke
parents:
diff changeset
400 return bot;
a61af66fc99e Initial load
duke
parents:
diff changeset
401
a61af66fc99e Initial load
duke
parents:
diff changeset
402 return sub(t1,t2); // Local flavor of type subtraction
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
407 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
408 Node *SubFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 const Type *t2 = phase->type( in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
410 // Convert "x-c0" into "x+ -c0".
a61af66fc99e Initial load
duke
parents:
diff changeset
411 if( t2->base() == Type::FloatCon ) { // Might be bottom or top...
a61af66fc99e Initial load
duke
parents:
diff changeset
412 // return new (phase->C, 3) AddFNode(in(1), phase->makecon( TypeF::make(-t2->getf()) ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 // Not associative because of boundary conditions (infinity)
a61af66fc99e Initial load
duke
parents:
diff changeset
416 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Convert "x - (x+y)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
418 if( in(2)->is_Add() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
419 phase->eqv(in(1),in(2)->in(1) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
420 return new (phase->C) SubFNode( phase->makecon(TypeF::ZERO),in(2)->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // Cannot replace 0.0-X with -X because a 'fsub' bytecode computes
a61af66fc99e Initial load
duke
parents:
diff changeset
424 // 0.0-0.0 as +0.0, while a 'fneg' bytecode computes -0.0.
a61af66fc99e Initial load
duke
parents:
diff changeset
425 //if( phase->type(in(1)) == TypeF::ZERO )
a61af66fc99e Initial load
duke
parents:
diff changeset
426 //return new (phase->C, 2) NegFNode(in(2));
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 //------------------------------sub--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // A subtract node differences its two inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
433 const Type *SubFNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // no folding if one of operands is infinity or NaN, do not do constant folding
a61af66fc99e Initial load
duke
parents:
diff changeset
435 if( g_isfinite(t1->getf()) && g_isfinite(t2->getf()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
436 return TypeF::make( t1->getf() - t2->getf() );
a61af66fc99e Initial load
duke
parents:
diff changeset
437 }
a61af66fc99e Initial load
duke
parents:
diff changeset
438 else if( g_isnan(t1->getf()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
439 return t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
441 else if( g_isnan(t2->getf()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 return t2;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 return Type::FLOAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
447 }
a61af66fc99e Initial load
duke
parents:
diff changeset
448
a61af66fc99e Initial load
duke
parents:
diff changeset
449 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
450 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
451 Node *SubDNode::Ideal(PhaseGVN *phase, bool can_reshape){
a61af66fc99e Initial load
duke
parents:
diff changeset
452 const Type *t2 = phase->type( in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // Convert "x-c0" into "x+ -c0".
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if( t2->base() == Type::DoubleCon ) { // Might be bottom or top...
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // return new (phase->C, 3) AddDNode(in(1), phase->makecon( TypeD::make(-t2->getd()) ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // Not associative because of boundary conditions (infinity)
a61af66fc99e Initial load
duke
parents:
diff changeset
459 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // Convert "x - (x+y)" into "-y"
a61af66fc99e Initial load
duke
parents:
diff changeset
461 if( in(2)->is_Add() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
462 phase->eqv(in(1),in(2)->in(1) ) )
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
463 return new (phase->C) SubDNode( phase->makecon(TypeD::ZERO),in(2)->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // Cannot replace 0.0-X with -X because a 'dsub' bytecode computes
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // 0.0-0.0 as +0.0, while a 'dneg' bytecode computes -0.0.
a61af66fc99e Initial load
duke
parents:
diff changeset
468 //if( phase->type(in(1)) == TypeD::ZERO )
a61af66fc99e Initial load
duke
parents:
diff changeset
469 //return new (phase->C, 2) NegDNode(in(2));
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 //------------------------------sub--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // A subtract node differences its two inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
476 const Type *SubDNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // no folding if one of operands is infinity or NaN, do not do constant folding
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if( g_isfinite(t1->getd()) && g_isfinite(t2->getd()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
479 return TypeD::make( t1->getd() - t2->getd() );
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 else if( g_isnan(t1->getd()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 return t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484 else if( g_isnan(t2->getd()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 return t2;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
487 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
493 //------------------------------Idealize---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // Unlike SubNodes, compare must still flatten return value to the
a61af66fc99e Initial load
duke
parents:
diff changeset
495 // range -1, 0, 1.
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // And optimizations like those for (X + Y) - X fail if overflow happens.
a61af66fc99e Initial load
duke
parents:
diff changeset
497 Node *CmpNode::Identity( PhaseTransform *phase ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
502 //------------------------------cmp--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // Simplify a CmpI (compare 2 integers) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
505 const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
506 const TypeInt *r0 = t1->is_int(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
507 const TypeInt *r1 = t2->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 if( r0->_hi < r1->_lo ) // Range is always low?
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 else if( r0->_lo > r1->_hi ) // Range is always high?
a61af66fc99e Initial load
duke
parents:
diff changeset
512 return TypeInt::CC_GT;
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
a61af66fc99e Initial load
duke
parents:
diff changeset
515 assert(r0->get_con() == r1->get_con(), "must be equal");
a61af66fc99e Initial load
duke
parents:
diff changeset
516 return TypeInt::CC_EQ; // Equal results.
a61af66fc99e Initial load
duke
parents:
diff changeset
517 } else if( r0->_hi == r1->_lo ) // Range is never high?
a61af66fc99e Initial load
duke
parents:
diff changeset
518 return TypeInt::CC_LE;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 else if( r0->_lo == r1->_hi ) // Range is never low?
a61af66fc99e Initial load
duke
parents:
diff changeset
520 return TypeInt::CC_GE;
a61af66fc99e Initial load
duke
parents:
diff changeset
521 return TypeInt::CC; // else use worst case results
a61af66fc99e Initial load
duke
parents:
diff changeset
522 }
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // Simplify a CmpU (compare 2 integers) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
526 const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 assert(!t1->isa_ptr(), "obsolete usage of CmpU");
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // comparing two unsigned ints
a61af66fc99e Initial load
duke
parents:
diff changeset
530 const TypeInt *r0 = t1->is_int(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
531 const TypeInt *r1 = t2->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // Current installed version
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // Compare ranges for non-overlap
a61af66fc99e Initial load
duke
parents:
diff changeset
535 juint lo0 = r0->_lo;
a61af66fc99e Initial load
duke
parents:
diff changeset
536 juint hi0 = r0->_hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
537 juint lo1 = r1->_lo;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 juint hi1 = r1->_hi;
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // If either one has both negative and positive values,
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // it therefore contains both 0 and -1, and since [0..-1] is the
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // full unsigned range, the type must act as an unsigned bottom.
a61af66fc99e Initial load
duke
parents:
diff changeset
543 bool bot0 = ((jint)(lo0 ^ hi0) < 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 bool bot1 = ((jint)(lo1 ^ hi1) < 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if (bot0 || bot1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 // All unsigned values are LE -1 and GE 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
548 if (lo0 == 0 && hi0 == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 return TypeInt::CC_LE; // 0 <= bot
a61af66fc99e Initial load
duke
parents:
diff changeset
550 } else if (lo1 == 0 && hi1 == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 return TypeInt::CC_GE; // bot >= 0
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // We can use ranges of the form [lo..hi] if signs are the same.
a61af66fc99e Initial load
duke
parents:
diff changeset
555 assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid");
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // results are reversed, '-' > '+' for unsigned compare
a61af66fc99e Initial load
duke
parents:
diff changeset
557 if (hi0 < lo1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 return TypeInt::CC_LT; // smaller
a61af66fc99e Initial load
duke
parents:
diff changeset
559 } else if (lo0 > hi1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
560 return TypeInt::CC_GT; // greater
a61af66fc99e Initial load
duke
parents:
diff changeset
561 } else if (hi0 == lo1 && lo0 == hi1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 return TypeInt::CC_EQ; // Equal results
a61af66fc99e Initial load
duke
parents:
diff changeset
563 } else if (lo0 >= hi1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 return TypeInt::CC_GE;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 } else if (hi0 <= lo1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // Check for special case in Hashtable::get. (See below.)
6207
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
567 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
0
a61af66fc99e Initial load
duke
parents:
diff changeset
568 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return TypeInt::CC_LE;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571 }
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // Check for special case in Hashtable::get - the hash index is
a61af66fc99e Initial load
duke
parents:
diff changeset
573 // mod'ed to the table size so the following range check is useless.
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have
a61af66fc99e Initial load
duke
parents:
diff changeset
575 // to be positive.
a61af66fc99e Initial load
duke
parents:
diff changeset
576 // (This is a gross hack, since the sub method never
a61af66fc99e Initial load
duke
parents:
diff changeset
577 // looks at the structure of the node in any other case.)
6207
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
578 if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
0
a61af66fc99e Initial load
duke
parents:
diff changeset
579 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
580 return TypeInt::CC; // else use worst case results
a61af66fc99e Initial load
duke
parents:
diff changeset
581 }
a61af66fc99e Initial load
duke
parents:
diff changeset
582
17936
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
583 const Type* CmpUNode::Value(PhaseTransform *phase) const {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
584 const Type* t = SubNode::Value_common(phase);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
585 if (t != NULL) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
586 return t;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
587 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
588 const Node* in1 = in(1);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
589 const Node* in2 = in(2);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
590 const Type* t1 = phase->type(in1);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
591 const Type* t2 = phase->type(in2);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
592 assert(t1->isa_int(), "CmpU has only Int type inputs");
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
593 if (t2 == TypeInt::INT) { // Compare to bottom?
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
594 return bottom_type();
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
595 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
596 uint in1_op = in1->Opcode();
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
597 if (in1_op == Op_AddI || in1_op == Op_SubI) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
598 // The problem rise when result of AddI(SubI) may overflow
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
599 // signed integer value. Let say the input type is
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
600 // [256, maxint] then +128 will create 2 ranges due to
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
601 // overflow: [minint, minint+127] and [384, maxint].
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
602 // But C2 type system keep only 1 type range and as result
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
603 // it use general [minint, maxint] for this case which we
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
604 // can't optimize.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
605 //
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
606 // Make 2 separate type ranges based on types of AddI(SubI) inputs
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
607 // and compare results of their compare. If results are the same
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
608 // CmpU node can be optimized.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
609 const Node* in11 = in1->in(1);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
610 const Node* in12 = in1->in(2);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
611 const Type* t11 = (in11 == in1) ? Type::TOP : phase->type(in11);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
612 const Type* t12 = (in12 == in1) ? Type::TOP : phase->type(in12);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
613 // Skip cases when input types are top or bottom.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
614 if ((t11 != Type::TOP) && (t11 != TypeInt::INT) &&
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
615 (t12 != Type::TOP) && (t12 != TypeInt::INT)) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
616 const TypeInt *r0 = t11->is_int();
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
617 const TypeInt *r1 = t12->is_int();
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
618 jlong lo_r0 = r0->_lo;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
619 jlong hi_r0 = r0->_hi;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
620 jlong lo_r1 = r1->_lo;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
621 jlong hi_r1 = r1->_hi;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
622 if (in1_op == Op_SubI) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
623 jlong tmp = hi_r1;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
624 hi_r1 = -lo_r1;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
625 lo_r1 = -tmp;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
626 // Note, for substructing [minint,x] type range
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
627 // long arithmetic provides correct overflow answer.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
628 // The confusion come from the fact that in 32-bit
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
629 // -minint == minint but in 64-bit -minint == maxint+1.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
630 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
631 jlong lo_long = lo_r0 + lo_r1;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
632 jlong hi_long = hi_r0 + hi_r1;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
633 int lo_tr1 = min_jint;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
634 int hi_tr1 = (int)hi_long;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
635 int lo_tr2 = (int)lo_long;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
636 int hi_tr2 = max_jint;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
637 bool underflow = lo_long != (jlong)lo_tr2;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
638 bool overflow = hi_long != (jlong)hi_tr1;
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
639 // Use sub(t1, t2) when there is no overflow (one type range)
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
640 // or when both overflow and underflow (too complex).
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
641 if ((underflow != overflow) && (hi_tr1 < lo_tr2)) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
642 // Overflow only on one boundary, compare 2 separate type ranges.
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
643 int w = MAX2(r0->_widen, r1->_widen); // _widen does not matter here
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
644 const TypeInt* tr1 = TypeInt::make(lo_tr1, hi_tr1, w);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
645 const TypeInt* tr2 = TypeInt::make(lo_tr2, hi_tr2, w);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
646 const Type* cmp1 = sub(tr1, t2);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
647 const Type* cmp2 = sub(tr2, t2);
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
648 if (cmp1 == cmp2) {
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
649 return cmp1; // Hit!
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
650 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
651 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
652 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
653 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
654
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
655 return sub(t1, t2); // Local flavor of type subtraction
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
656 }
968a17f18337 8042786: Proper fix for 8032566
kvn
parents: 14495
diff changeset
657
6207
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
658 bool CmpUNode::is_index_range_check() const {
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
659 // Check for the "(X ModI Y) CmpU Y" shape
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
660 return (in(1)->Opcode() == Op_ModI &&
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
661 in(1)->in(2)->eqv_uncast(in(2)));
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
662 }
ae9241bbce4a 7181658: CTW: assert(t->meet(t0) == t) failed: Not monotonic
kvn
parents: 6131
diff changeset
663
0
a61af66fc99e Initial load
duke
parents:
diff changeset
664 //------------------------------Idealize---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
665 Node *CmpINode::Ideal( PhaseGVN *phase, bool can_reshape ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 if (phase->type(in(2))->higher_equal(TypeInt::ZERO)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 switch (in(1)->Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
668 case Op_CmpL3: // Collapse a CmpL3/CmpI into a CmpL
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
669 return new (phase->C) CmpLNode(in(1)->in(1),in(1)->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
670 case Op_CmpF3: // Collapse a CmpF3/CmpI into a CmpF
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
671 return new (phase->C) CmpFNode(in(1)->in(1),in(1)->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
672 case Op_CmpD3: // Collapse a CmpD3/CmpI into a CmpD
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
673 return new (phase->C) CmpDNode(in(1)->in(1),in(1)->in(2));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
674 //case Op_SubI:
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // If (x - y) cannot overflow, then ((x - y) <?> 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // can be turned into (x <?> y).
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // This is handled (with more general cases) by Ideal_sub_algebra.
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
679 }
a61af66fc99e Initial load
duke
parents:
diff changeset
680 return NULL; // No change
a61af66fc99e Initial load
duke
parents:
diff changeset
681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // Simplify a CmpL (compare 2 longs ) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
687 const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
688 const TypeLong *r0 = t1->is_long(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
689 const TypeLong *r1 = t2->is_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 if( r0->_hi < r1->_lo ) // Range is always low?
a61af66fc99e Initial load
duke
parents:
diff changeset
692 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
693 else if( r0->_lo > r1->_hi ) // Range is always high?
a61af66fc99e Initial load
duke
parents:
diff changeset
694 return TypeInt::CC_GT;
a61af66fc99e Initial load
duke
parents:
diff changeset
695
a61af66fc99e Initial load
duke
parents:
diff changeset
696 else if( r0->is_con() && r1->is_con() ) { // comparing constants?
a61af66fc99e Initial load
duke
parents:
diff changeset
697 assert(r0->get_con() == r1->get_con(), "must be equal");
a61af66fc99e Initial load
duke
parents:
diff changeset
698 return TypeInt::CC_EQ; // Equal results.
a61af66fc99e Initial load
duke
parents:
diff changeset
699 } else if( r0->_hi == r1->_lo ) // Range is never high?
a61af66fc99e Initial load
duke
parents:
diff changeset
700 return TypeInt::CC_LE;
a61af66fc99e Initial load
duke
parents:
diff changeset
701 else if( r0->_lo == r1->_hi ) // Range is never low?
a61af66fc99e Initial load
duke
parents:
diff changeset
702 return TypeInt::CC_GE;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 return TypeInt::CC; // else use worst case results
a61af66fc99e Initial load
duke
parents:
diff changeset
704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
707 //------------------------------sub--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // Simplify an CmpP (compare 2 pointers) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
709 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
710 const Type *CmpPNode::sub( const Type *t1, const Type *t2 ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
711 const TypePtr *r0 = t1->is_ptr(); // Handy access
a61af66fc99e Initial load
duke
parents:
diff changeset
712 const TypePtr *r1 = t2->is_ptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 // Undefined inputs makes for an undefined result
a61af66fc99e Initial load
duke
parents:
diff changeset
715 if( TypePtr::above_centerline(r0->_ptr) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
716 TypePtr::above_centerline(r1->_ptr) )
a61af66fc99e Initial load
duke
parents:
diff changeset
717 return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 if (r0 == r1 && r0->singleton()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // Equal pointer constants (klasses, nulls, etc.)
a61af66fc99e Initial load
duke
parents:
diff changeset
721 return TypeInt::CC_EQ;
a61af66fc99e Initial load
duke
parents:
diff changeset
722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 // See if it is 2 unrelated classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
725 const TypeOopPtr* p0 = r0->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
726 const TypeOopPtr* p1 = r1->isa_oopptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
727 if (p0 && p1) {
33
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
728 Node* in1 = in(1)->uncast();
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
729 Node* in2 = in(2)->uncast();
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
730 AllocateNode* alloc1 = AllocateNode::Ideal_allocation(in1, NULL);
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
731 AllocateNode* alloc2 = AllocateNode::Ideal_allocation(in2, NULL);
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
732 if (MemNode::detect_ptr_independence(in1, alloc1, in2, alloc2, NULL)) {
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
733 return TypeInt::CC_GT; // different pointers
3288958bf319 6667580: Optimize CmpP for allocations
kvn
parents: 0
diff changeset
734 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
735 ciKlass* klass0 = p0->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
736 bool xklass0 = p0->klass_is_exact();
a61af66fc99e Initial load
duke
parents:
diff changeset
737 ciKlass* klass1 = p1->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
738 bool xklass1 = p1->klass_is_exact();
a61af66fc99e Initial load
duke
parents:
diff changeset
739 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
a61af66fc99e Initial load
duke
parents:
diff changeset
740 if (klass0 && klass1 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
741 kps != 1 && // both or neither are klass pointers
668
90a66aa50514 6820510: assertion failure with unloaded class in subnode.cpp
never
parents: 400
diff changeset
742 klass0->is_loaded() && !klass0->is_interface() && // do not trust interfaces
783
a9e116455022 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 668
diff changeset
743 klass1->is_loaded() && !klass1->is_interface() &&
a9e116455022 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 668
diff changeset
744 (!klass0->is_obj_array_klass() ||
a9e116455022 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 668
diff changeset
745 !klass0->as_obj_array_klass()->base_element_klass()->is_interface()) &&
a9e116455022 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 668
diff changeset
746 (!klass1->is_obj_array_klass() ||
a9e116455022 6832293: JIT compiler got wrong result in type checking with -server
kvn
parents: 668
diff changeset
747 !klass1->as_obj_array_klass()->base_element_klass()->is_interface())) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
748 bool unrelated_classes = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
749 // See if neither subclasses the other, or if the class on top
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
750 // is precise. In either of these cases, the compare is known
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
751 // to fail if at least one of the pointers is provably not null.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6207
diff changeset
752 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal
0
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // Do nothing; we know nothing for imprecise types
a61af66fc99e Initial load
duke
parents:
diff changeset
754 } else if (klass0->is_subtype_of(klass1)) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
755 // If klass1's type is PRECISE, then classes are unrelated.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
756 unrelated_classes = xklass1;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
757 } else if (klass1->is_subtype_of(klass0)) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
758 // If klass0's type is PRECISE, then classes are unrelated.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
759 unrelated_classes = xklass0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
760 } else { // Neither subtypes the other
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
761 unrelated_classes = true;
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
762 }
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
763 if (unrelated_classes) {
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
764 // The oops classes are known to be unrelated. If the joined PTRs of
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
765 // two oops is not Null and not Bottom, then we are sure that one
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
766 // of the two oops is non-null, and the comparison will always fail.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
767 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
768 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
769 return TypeInt::CC_GT;
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
770 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774
a61af66fc99e Initial load
duke
parents:
diff changeset
775 // Known constants can be compared exactly
a61af66fc99e Initial load
duke
parents:
diff changeset
776 // Null can be distinguished from any NotNull pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
777 // Unknown inputs makes an unknown result
a61af66fc99e Initial load
duke
parents:
diff changeset
778 if( r0->singleton() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 intptr_t bits0 = r0->get_con();
a61af66fc99e Initial load
duke
parents:
diff changeset
780 if( r1->singleton() )
a61af66fc99e Initial load
duke
parents:
diff changeset
781 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
a61af66fc99e Initial load
duke
parents:
diff changeset
783 } else if( r1->singleton() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
784 intptr_t bits1 = r1->get_con();
a61af66fc99e Initial load
duke
parents:
diff changeset
785 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
787 return TypeInt::CC;
a61af66fc99e Initial load
duke
parents:
diff changeset
788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
789
6131
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
790 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
791 // Return the klass node for
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
792 // LoadP(AddP(foo:Klass, #java_mirror))
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
793 // or NULL if not matching.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
794 if (n->Opcode() != Op_LoadP) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
795
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
796 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
797 if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
798
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
799 Node* adr = n->in(MemNode::Address);
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
800 intptr_t off = 0;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
801 Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
802 if (k == NULL) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
803 const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
804 if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
805
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
806 // We've found the klass node of a Java mirror load.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
807 return k;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
808 }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
809
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
810 static inline Node* isa_const_java_mirror(PhaseGVN* phase, Node* n) {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
811 // for ConP(Foo.class) return ConP(Foo.klass)
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
812 // otherwise return NULL
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
813 if (!n->is_Con()) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
814
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
815 const TypeInstPtr* tp = phase->type(n)->isa_instptr();
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
816 if (!tp) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
817
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
818 ciType* mirror_type = tp->java_mirror_type();
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
819 // TypeInstPtr::java_mirror_type() returns non-NULL for compile-
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
820 // time Class constants only.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
821 if (!mirror_type) return NULL;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
822
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
823 // x.getClass() == int.class can never be true (for all primitive types)
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
824 // Return a ConP(NULL) node for this case.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
825 if (mirror_type->is_classless()) {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
826 return phase->makecon(TypePtr::NULL_PTR);
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
827 }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
828
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
829 // return the ConP(Foo.klass)
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6207
diff changeset
830 assert(mirror_type->is_klass(), "mirror_type should represent a Klass*");
6131
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
831 return phase->makecon(TypeKlassPtr::make(mirror_type->as_klass()));
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
832 }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
833
0
a61af66fc99e Initial load
duke
parents:
diff changeset
834 //------------------------------Ideal------------------------------------------
6131
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
835 // Normalize comparisons between Java mirror loads to compare the klass instead.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
836 //
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
837 // Also check for the case of comparing an unknown klass loaded from the primary
0
a61af66fc99e Initial load
duke
parents:
diff changeset
838 // super-type array vs a known klass with no subtypes. This amounts to
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // checking to see an unknown klass subtypes a known klass with no subtypes;
a61af66fc99e Initial load
duke
parents:
diff changeset
840 // this only happens on an exact match. We can shorten this test by 1 load.
a61af66fc99e Initial load
duke
parents:
diff changeset
841 Node *CmpPNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
6131
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
842 // Normalize comparisons between Java mirrors into comparisons of the low-
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
843 // level klass, where a dependent load could be shortened.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
844 //
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
845 // The new pattern has a nice effect of matching the same pattern used in the
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
846 // fast path of instanceof/checkcast/Class.isInstance(), which allows
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
847 // redundant exact type check be optimized away by GVN.
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
848 // For example, in
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
849 // if (x.getClass() == Foo.class) {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
850 // Foo foo = (Foo) x;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
851 // // ... use a ...
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
852 // }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
853 // a CmpPNode could be shared between if_acmpne and checkcast
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
854 {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
855 Node* k1 = isa_java_mirror_load(phase, in(1));
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
856 Node* k2 = isa_java_mirror_load(phase, in(2));
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
857 Node* conk2 = isa_const_java_mirror(phase, in(2));
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
858
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
859 if (k1 && (k2 || conk2)) {
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
860 Node* lhs = k1;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
861 Node* rhs = (k2 != NULL) ? k2 : conk2;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
862 this->set_req(1, lhs);
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
863 this->set_req(2, rhs);
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
864 return this;
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
865 }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
866 }
8f6ce6f1049b 7170463: C2 should recognize "obj.getClass() == A.class" code pattern
kvn
parents: 6084
diff changeset
867
0
a61af66fc99e Initial load
duke
parents:
diff changeset
868 // Constant pointer on right?
a61af66fc99e Initial load
duke
parents:
diff changeset
869 const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
a61af66fc99e Initial load
duke
parents:
diff changeset
870 if (t2 == NULL || !t2->klass_is_exact())
a61af66fc99e Initial load
duke
parents:
diff changeset
871 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
872 // Get the constant klass we are comparing to.
a61af66fc99e Initial load
duke
parents:
diff changeset
873 ciKlass* superklass = t2->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
874
a61af66fc99e Initial load
duke
parents:
diff changeset
875 // Now check for LoadKlass on left.
a61af66fc99e Initial load
duke
parents:
diff changeset
876 Node* ldk1 = in(1);
6848
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 6804
diff changeset
877 if (ldk1->is_DecodeNKlass()) {
293
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
878 ldk1 = ldk1->in(1);
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
879 if (ldk1->Opcode() != Op_LoadNKlass )
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
880 return NULL;
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
881 } else if (ldk1->Opcode() != Op_LoadKlass )
0
a61af66fc99e Initial load
duke
parents:
diff changeset
882 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
883 // Take apart the address of the LoadKlass:
a61af66fc99e Initial load
duke
parents:
diff changeset
884 Node* adr1 = ldk1->in(MemNode::Address);
a61af66fc99e Initial load
duke
parents:
diff changeset
885 intptr_t con2 = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
886 Node* ldk2 = AddPNode::Ideal_base_and_offset(adr1, phase, con2);
a61af66fc99e Initial load
duke
parents:
diff changeset
887 if (ldk2 == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
888 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
889 if (con2 == oopDesc::klass_offset_in_bytes()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
890 // We are inspecting an object's concrete class.
a61af66fc99e Initial load
duke
parents:
diff changeset
891 // Short-circuit the check if the query is abstract.
a61af66fc99e Initial load
duke
parents:
diff changeset
892 if (superklass->is_interface() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
893 superklass->is_abstract()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
894 // Make it come out always false:
a61af66fc99e Initial load
duke
parents:
diff changeset
895 this->set_req(2, phase->makecon(TypePtr::NULL_PTR));
a61af66fc99e Initial load
duke
parents:
diff changeset
896 return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
897 }
a61af66fc99e Initial load
duke
parents:
diff changeset
898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
899
a61af66fc99e Initial load
duke
parents:
diff changeset
900 // Check for a LoadKlass from primary supertype array.
a61af66fc99e Initial load
duke
parents:
diff changeset
901 // Any nested loadklass from loadklass+con must be from the p.s. array.
6848
8e47bac5643a 7054512: Compress class pointers after perm gen removal
roland
parents: 6804
diff changeset
902 if (ldk2->is_DecodeNKlass()) {
293
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
903 // Keep ldk2 as DecodeN since it could be used in CmpP below.
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
904 if (ldk2->in(1)->Opcode() != Op_LoadNKlass )
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
905 return NULL;
c3e045194476 6731641: assert(m->adr_type() == mach->adr_type(),"matcher should not change adr type")
kvn
parents: 235
diff changeset
906 } else if (ldk2->Opcode() != Op_LoadKlass)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
907 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
908
a61af66fc99e Initial load
duke
parents:
diff changeset
909 // Verify that we understand the situation
a61af66fc99e Initial load
duke
parents:
diff changeset
910 if (con2 != (intptr_t) superklass->super_check_offset())
a61af66fc99e Initial load
duke
parents:
diff changeset
911 return NULL; // Might be element-klass loading from array klass
a61af66fc99e Initial load
duke
parents:
diff changeset
912
a61af66fc99e Initial load
duke
parents:
diff changeset
913 // If 'superklass' has no subklasses and is not an interface, then we are
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // assured that the only input which will pass the type check is
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // 'superklass' itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
916 //
a61af66fc99e Initial load
duke
parents:
diff changeset
917 // We could be more liberal here, and allow the optimization on interfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
918 // which have a single implementor. This would require us to increase the
a61af66fc99e Initial load
duke
parents:
diff changeset
919 // expressiveness of the add_dependency() mechanism.
a61af66fc99e Initial load
duke
parents:
diff changeset
920 // %%% Do this after we fix TypeOopPtr: Deps are expressive enough now.
a61af66fc99e Initial load
duke
parents:
diff changeset
921
a61af66fc99e Initial load
duke
parents:
diff changeset
922 // Object arrays must have their base element have no subtypes
a61af66fc99e Initial load
duke
parents:
diff changeset
923 while (superklass->is_obj_array_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
924 ciType* elem = superklass->as_obj_array_klass()->element_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
925 superklass = elem->as_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
927 if (superklass->is_instance_klass()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
928 ciInstanceKlass* ik = superklass->as_instance_klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if (ik->has_subklass() || ik->is_interface()) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 // Add a dependency if there is a chance that a subclass will be added later.
a61af66fc99e Initial load
duke
parents:
diff changeset
931 if (!ik->is_final()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 phase->C->dependencies()->assert_leaf_type(ik);
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // Bypass the dependent load, and compare directly
a61af66fc99e Initial load
duke
parents:
diff changeset
937 this->set_req(1,ldk2);
a61af66fc99e Initial load
duke
parents:
diff changeset
938
a61af66fc99e Initial load
duke
parents:
diff changeset
939 return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941
a61af66fc99e Initial load
duke
parents:
diff changeset
942 //=============================================================================
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
943 //------------------------------sub--------------------------------------------
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
944 // Simplify an CmpN (compare 2 pointers) node, based on local information.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
945 // If both inputs are constants, compare them.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
946 const Type *CmpNNode::sub( const Type *t1, const Type *t2 ) const {
221
1e026f8da827 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 212
diff changeset
947 const TypePtr *r0 = t1->make_ptr(); // Handy access
1e026f8da827 6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents: 212
diff changeset
948 const TypePtr *r1 = t2->make_ptr();
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
949
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
950 // Undefined inputs makes for an undefined result
10279
70120f47d403 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 9060
diff changeset
951 if ((r0 == NULL) || (r1 == NULL) ||
70120f47d403 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 9060
diff changeset
952 TypePtr::above_centerline(r0->_ptr) ||
70120f47d403 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 9060
diff changeset
953 TypePtr::above_centerline(r1->_ptr)) {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
954 return Type::TOP;
10279
70120f47d403 8014189: JVM crash with SEGV in ConnectionGraph::record_for_escape_analysis()
kvn
parents: 9060
diff changeset
955 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
956 if (r0 == r1 && r0->singleton()) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
957 // Equal pointer constants (klasses, nulls, etc.)
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
958 return TypeInt::CC_EQ;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
959 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
960
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
961 // See if it is 2 unrelated classes.
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
962 const TypeOopPtr* p0 = r0->isa_oopptr();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
963 const TypeOopPtr* p1 = r1->isa_oopptr();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
964 if (p0 && p1) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
965 ciKlass* klass0 = p0->klass();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
966 bool xklass0 = p0->klass_is_exact();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
967 ciKlass* klass1 = p1->klass();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
968 bool xklass1 = p1->klass_is_exact();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
969 int kps = (p0->isa_klassptr()?1:0) + (p1->isa_klassptr()?1:0);
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
970 if (klass0 && klass1 &&
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
971 kps != 1 && // both or neither are klass pointers
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
972 !klass0->is_interface() && // do not trust interfaces
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
973 !klass1->is_interface()) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
974 bool unrelated_classes = false;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
975 // See if neither subclasses the other, or if the class on top
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
976 // is precise. In either of these cases, the compare is known
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
977 // to fail if at least one of the pointers is provably not null.
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6207
diff changeset
978 if (klass0->equals(klass1)) { // if types are unequal but klasses are equal
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
979 // Do nothing; we know nothing for imprecise types
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
980 } else if (klass0->is_subtype_of(klass1)) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
981 // If klass1's type is PRECISE, then classes are unrelated.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
982 unrelated_classes = xklass1;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
983 } else if (klass1->is_subtype_of(klass0)) {
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
984 // If klass0's type is PRECISE, then classes are unrelated.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
985 unrelated_classes = xklass0;
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
986 } else { // Neither subtypes the other
296
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
987 unrelated_classes = true;
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
988 }
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
989 if (unrelated_classes) {
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
990 // The oops classes are known to be unrelated. If the joined PTRs of
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
991 // two oops is not Null and not Bottom, then we are sure that one
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
992 // of the two oops is non-null, and the comparison will always fail.
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
993 TypePtr::PTR jp = r0->join_ptr(r1->_ptr);
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
994 if (jp != TypePtr::Null && jp != TypePtr::BotPTR) {
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
995 return TypeInt::CC_GT;
ce93a51457ae 6730716: nulls from two unrelated classes compare not equal
rasbold
parents: 293
diff changeset
996 }
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
997 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
998 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
999 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1000
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1001 // Known constants can be compared exactly
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1002 // Null can be distinguished from any NotNull pointers
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1003 // Unknown inputs makes an unknown result
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1004 if( r0->singleton() ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1005 intptr_t bits0 = r0->get_con();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1006 if( r1->singleton() )
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1007 return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1008 return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1009 } else if( r1->singleton() ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1010 intptr_t bits1 = r1->get_con();
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1011 return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1012 } else
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1013 return TypeInt::CC;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1014 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1015
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1016 //------------------------------Ideal------------------------------------------
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1017 Node *CmpNNode::Ideal( PhaseGVN *phase, bool can_reshape ) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1018 return NULL;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1019 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1020
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 33
diff changeset
1021 //=============================================================================
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 // Simplify an CmpF (compare 2 floats ) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 const Type *CmpFNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 const Node* in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 const Node* in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 // Either input is TOP ==> the result is TOP
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 if( t2 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1033
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 // Not constants? Don't know squat - even if they are the same
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 // value! If they are NaN's they compare to LT instead of EQ.
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 const TypeF *tf1 = t1->isa_float_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 const TypeF *tf2 = t2->isa_float_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 if( !tf1 || !tf2 ) return TypeInt::CC;
a61af66fc99e Initial load
duke
parents:
diff changeset
1039
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 // This implements the Java bytecode fcmpl, so unordered returns -1.
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 if( tf1->is_nan() || tf2->is_nan() )
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1043
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 if( tf1->_f < tf2->_f ) return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 if( tf1->_f > tf2->_f ) return TypeInt::CC_GT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 assert( tf1->_f == tf2->_f, "do not understand FP behavior" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 return TypeInt::CC_EQ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1049
a61af66fc99e Initial load
duke
parents:
diff changeset
1050
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 // Simplify an CmpD (compare 2 doubles ) node, based on local information.
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 // If both inputs are constants, compare them.
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 const Type *CmpDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 const Node* in1 = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 const Node* in2 = in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // Either input is TOP ==> the result is TOP
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 const Type* t1 = (in1 == this) ? Type::TOP : phase->type(in1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 const Type* t2 = (in2 == this) ? Type::TOP : phase->type(in2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 if( t2 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1063
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 // Not constants? Don't know squat - even if they are the same
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 // value! If they are NaN's they compare to LT instead of EQ.
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 const TypeD *td1 = t1->isa_double_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 const TypeD *td2 = t2->isa_double_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 if( !td1 || !td2 ) return TypeInt::CC;
a61af66fc99e Initial load
duke
parents:
diff changeset
1069
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 // This implements the Java bytecode dcmpl, so unordered returns -1.
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 if( td1->is_nan() || td2->is_nan() )
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1073
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 if( td1->_d < td2->_d ) return TypeInt::CC_LT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 if( td1->_d > td2->_d ) return TypeInt::CC_GT;
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 assert( td1->_d == td2->_d, "do not understand FP behavior" );
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 return TypeInt::CC_EQ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1079
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 Node *CmpDNode::Ideal(PhaseGVN *phase, bool can_reshape){
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 // Check if we can change this to a CmpF and remove a ConvD2F operation.
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 // Change (CMPD (F2D (float)) (ConD value))
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 // To (CMPF (float) (ConF value))
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 // Valid when 'value' does not lose precision as a float.
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 // Benefits: eliminates conversion, does not require 24-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
1087
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 // NaNs prevent commuting operands. This transform works regardless of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 // order of ConD and ConvF2D inputs by preserving the original order.
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 int idx_f2d = 1; // ConvF2D on left side?
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 if( in(idx_f2d)->Opcode() != Op_ConvF2D )
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 idx_f2d = 2; // No, swap to check for reversed args
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 int idx_con = 3-idx_f2d; // Check for the constant on other input
a61af66fc99e Initial load
duke
parents:
diff changeset
1094
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 if( ConvertCmpD2CmpF &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 in(idx_f2d)->Opcode() == Op_ConvF2D &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 in(idx_con)->Opcode() == Op_ConD ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 const TypeD *t2 = in(idx_con)->bottom_type()->is_double_constant();
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 double t2_value_as_double = t2->_d;
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 float t2_value_as_float = (float)t2_value_as_double;
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 if( t2_value_as_double == (double)t2_value_as_float ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 // Test value can be represented as a float
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 // Eliminate the conversion to double and create new comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 Node *new_in1 = in(idx_f2d)->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 Node *new_in2 = phase->makecon( TypeF::make(t2_value_as_float) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 if( idx_f2d != 1 ) { // Must flip args to match original order
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 Node *tmp = new_in1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 new_in1 = new_in2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 new_in2 = tmp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 CmpFNode *new_cmp = (Opcode() == Op_CmpD3)
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1112 ? new (phase->C) CmpF3Node( new_in1, new_in2 )
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1113 : new (phase->C) CmpFNode ( new_in1, new_in2 ) ;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 return new_cmp; // Changed to CmpFNode
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 // Testing value required the precision of a double
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 return NULL; // No change
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1120
a61af66fc99e Initial load
duke
parents:
diff changeset
1121
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 //------------------------------cc2logical-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 // Convert a condition code type to a logical type
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 const Type *BoolTest::cc2logical( const Type *CC ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 if( CC == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 if( CC->base() != Type::Int ) return TypeInt::BOOL; // Bottom or worse
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 const TypeInt *ti = CC->is_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 if( ti->is_con() ) { // Only 1 kind of condition codes set?
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 // Match low order 2 bits
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 int tmp = ((ti->get_con()&3) == (_test&3)) ? 1 : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 if( _test & 4 ) tmp = 1-tmp; // Optionally complement result
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 return TypeInt::make(tmp); // Boolean result
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 if( CC == TypeInt::CC_GE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 if( _test == ge ) return TypeInt::ONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 if( _test == lt ) return TypeInt::ZERO;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if( CC == TypeInt::CC_LE ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 if( _test == le ) return TypeInt::ONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 if( _test == gt ) return TypeInt::ZERO;
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1144
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 return TypeInt::BOOL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1147
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 //------------------------------dump_spec-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 // Print special per-node info
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 void BoolTest::dump_on(outputStream *st) const {
12323
c9ccd7b85f20 8024924: Intrinsify java.lang.Math.addExact
rbackman
parents: 10279
diff changeset
1151 const char *msg[] = {"eq","gt","of","lt","ne","le","nof","ge"};
17937
78bbf4d43a14 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 14495
diff changeset
1152 st->print("%s", msg[_test]);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1154
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 uint BoolNode::hash() const { return (Node::hash() << 3)|(_test._test+1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 uint BoolNode::size_of() const { return sizeof(BoolNode); }
a61af66fc99e Initial load
duke
parents:
diff changeset
1158
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 //------------------------------operator==-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 uint BoolNode::cmp( const Node &n ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 const BoolNode *b = (const BoolNode *)&n; // Cast up
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 return (_test._test == b->_test._test);
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1164
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 //-------------------------------make_predicate--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 Node* BoolNode::make_predicate(Node* test_value, PhaseGVN* phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 if (test_value->is_Con()) return test_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 if (test_value->is_Bool()) return test_value;
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 Compile* C = phase->C;
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 if (test_value->is_CMove() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 test_value->in(CMoveNode::Condition)->is_Bool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 BoolNode* bol = test_value->in(CMoveNode::Condition)->as_Bool();
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 const Type* ftype = phase->type(test_value->in(CMoveNode::IfFalse));
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 const Type* ttype = phase->type(test_value->in(CMoveNode::IfTrue));
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 if (ftype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ttype)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 return bol;
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 } else if (ttype == TypeInt::ZERO && !TypeInt::ZERO->higher_equal(ftype)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 return phase->transform( bol->negate(phase) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 // Else fall through. The CMove gets in the way of the test.
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 // It should be the case that make_predicate(bol->as_int_value()) == bol.
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 }
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1183 Node* cmp = new (C) CmpINode(test_value, phase->intcon(0));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 cmp = phase->transform(cmp);
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1185 Node* bol = new (C) BoolNode(cmp, BoolTest::ne);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 return phase->transform(bol);
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1188
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 //--------------------------------as_int_value---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 Node* BoolNode::as_int_value(PhaseGVN* phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 // Inverse to make_predicate. The CMove probably boils down to a Conv2B.
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 Node* cmov = CMoveNode::make(phase->C, NULL, this,
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 phase->intcon(0), phase->intcon(1),
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 TypeInt::BOOL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 return phase->transform(cmov);
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1197
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 //----------------------------------negate-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 BoolNode* BoolNode::negate(PhaseGVN* phase) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 Compile* C = phase->C;
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1201 return new (C) BoolNode(in(1), _test.negate());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1203
a61af66fc99e Initial load
duke
parents:
diff changeset
1204
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 //------------------------------Ideal------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 // Change "bool tst (cmp con x)" into "bool ~tst (cmp x con)".
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 // This moves the constant to the right. Helps value-numbering.
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 Node *cmp = in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 if( !cmp->is_Sub() ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 int cop = cmp->Opcode();
14495
cd5d10655495 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 14223
diff changeset
1212 if( cop == Op_FastLock || cop == Op_FastUnlock) return NULL;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 Node *cmp1 = cmp->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 Node *cmp2 = cmp->in(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 if( !cmp1 ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1216
14495
cd5d10655495 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 14223
diff changeset
1217 if (_test._test == BoolTest::overflow || _test._test == BoolTest::no_overflow) {
cd5d10655495 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 14223
diff changeset
1218 return NULL;
cd5d10655495 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 14223
diff changeset
1219 }
cd5d10655495 8027754: Enable loop optimizations for loops with MathExact inside
rbackman
parents: 14223
diff changeset
1220
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // Constant on left?
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 Node *con = cmp1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 uint op2 = cmp2->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 // Move constants to the right of compare's to canonicalize.
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 // Do not muck with Opaque1 nodes, as this indicates a loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 // guard that cannot change shape.
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 if( con->is_Con() && !cmp2->is_Con() && op2 != Op_Opaque1 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 // Because of NaN's, CmpD and CmpF are not commutative
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 cop != Op_CmpD && cop != Op_CmpF &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 // Protect against swapping inputs to a compare when it is used by a
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 // counted loop exit, which requires maintaining the loop-limit as in(2)
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 !is_counted_loop_exit_test() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 // Ok, commute the constant to the right of the cmp node.
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 // Clone the Node, getting a new Node of the same class
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 cmp = cmp->clone();
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 // Swap inputs to the clone
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 cmp->swap_edges(1, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 cmp = phase->transform( cmp );
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1239 return new (phase->C) BoolNode( cmp, _test.commute() );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1241
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 // Change "bool eq/ne (cmp (xor X 1) 0)" into "bool ne/eq (cmp X 0)".
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 // The XOR-1 is an idiom used to flip the sense of a bool. We flip the
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 // test instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 int cmp1_op = cmp1->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 const TypeInt* cmp2_type = phase->type(cmp2)->isa_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 if (cmp2_type == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 Node* j_xor = cmp1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 if( cmp2_type == TypeInt::ZERO &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 cmp1_op == Op_XorI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 j_xor->in(1) != j_xor && // An xor of itself is dead
3416
f88fb2fa90cf 6956668: misbehavior of XOR operator (^) with int
kvn
parents: 3338
diff changeset
1252 phase->type( j_xor->in(1) ) == TypeInt::BOOL &&
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 phase->type( j_xor->in(2) ) == TypeInt::ONE &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 (_test._test == BoolTest::eq ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 _test._test == BoolTest::ne) ) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1256 Node *ncmp = phase->transform(new (phase->C) CmpINode(j_xor->in(1),cmp2));
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1257 return new (phase->C) BoolNode( ncmp, _test.negate() );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1259
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 // Change "bool eq/ne (cmp (Conv2B X) 0)" into "bool eq/ne (cmp X 0)".
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 // This is a standard idiom for branching on a boolean value.
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 Node *c2b = cmp1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 if( cmp2_type == TypeInt::ZERO &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 cmp1_op == Op_Conv2B &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 (_test._test == BoolTest::eq ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 _test._test == BoolTest::ne) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 Node *ncmp = phase->transform(phase->type(c2b->in(1))->isa_int()
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1268 ? (Node*)new (phase->C) CmpINode(c2b->in(1),cmp2)
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1269 : (Node*)new (phase->C) CmpPNode(c2b->in(1),phase->makecon(TypePtr::NULL_PTR))
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 );
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1271 return new (phase->C) BoolNode( ncmp, _test._test );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1273
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 // Comparing a SubI against a zero is equal to comparing the SubI
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 // arguments directly. This only works for eq and ne comparisons
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 // due to possible integer overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 if ((_test._test == BoolTest::eq || _test._test == BoolTest::ne) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 (cop == Op_CmpI) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 (cmp1->Opcode() == Op_SubI) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 ( cmp2_type == TypeInt::ZERO ) ) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1281 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(1),cmp1->in(2)));
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1282 return new (phase->C) BoolNode( ncmp, _test._test );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1284
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 // Change (-A vs 0) into (A vs 0) by commuting the test. Disallow in the
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 // most general case because negating 0x80000000 does nothing. Needed for
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 // the CmpF3/SubI/CmpI idiom.
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 if( cop == Op_CmpI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 cmp1->Opcode() == Op_SubI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 cmp2_type == TypeInt::ZERO &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 phase->type( cmp1->in(1) ) == TypeInt::ZERO &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 phase->type( cmp1->in(2) )->higher_equal(TypeInt::SYMINT) ) {
6804
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1293 Node *ncmp = phase->transform( new (phase->C) CmpINode(cmp1->in(2),cmp2));
e626685e9f6c 7193318: C2: remove number of inputs requirement from Node's new operator
kvn
parents: 6725
diff changeset
1294 return new (phase->C) BoolNode( ncmp, _test.commute() );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1296
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 // The transformation below is not valid for either signed or unsigned
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 // comparisons due to wraparound concerns at MAX_VALUE and MIN_VALUE.
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 // This transformation can be resurrected when we are able to
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 // make inferences about the range of values being subtracted from
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 // (or added to) relative to the wraparound point.
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 // // Remove +/-1's if possible.
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // // "X <= Y-1" becomes "X < Y"
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 // // "X+1 <= Y" becomes "X < Y"
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 // // "X < Y+1" becomes "X <= Y"
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 // // "X-1 < Y" becomes "X <= Y"
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 // // Do not this to compares off of the counted-loop-end. These guys are
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 // // checking the trip counter and they want to use the post-incremented
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 // // counter. If they use the PRE-incremented counter, then the counter has
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 // // to be incremented in a private block on a loop backedge.
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 // if( du && du->cnt(this) && du->out(this)[0]->Opcode() == Op_CountedLoopEnd )
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 // return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 // #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 // // Do not do this in a wash GVN pass during verification.
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 // // Gets triggered by too many simple optimizations to be bothered with
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 // // re-trying it again and again.
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 // if( !phase->allow_progress() ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 // #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 // // Not valid for unsigned compare because of corner cases in involving zero.
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 // // For example, replacing "X-1 <u Y" with "X <=u Y" fails to throw an
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 // // exception in case X is 0 (because 0-1 turns into 4billion unsigned but
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 // // "0 <=u Y" is always true).
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 // if( cmp->Opcode() == Op_CmpU ) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 // int cmp2_op = cmp2->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 // if( _test._test == BoolTest::le ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 // if( cmp1_op == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 // phase->type( cmp1->in(2) ) == TypeInt::ONE )
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::lt );
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 // else if( cmp2_op == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 // phase->type( cmp2->in(2) ) == TypeInt::MINUS_1 )
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::lt );
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 // } else if( _test._test == BoolTest::lt ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 // if( cmp1_op == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 // phase->type( cmp1->in(2) ) == TypeInt::MINUS_1 )
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 // return clone_cmp( cmp, cmp1->in(1), cmp2, phase, BoolTest::le );
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 // else if( cmp2_op == Op_AddI &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 // phase->type( cmp2->in(2) ) == TypeInt::ONE )
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 // return clone_cmp( cmp, cmp1, cmp2->in(1), phase, BoolTest::le );
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1341
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1344
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 // Simplify a Bool (convert condition codes to boolean (1 or 0)) node,
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 // based on local information. If the input is constant, do it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 const Type *BoolNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 return _test.cc2logical( phase->type( in(1) ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1351
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 //------------------------------dump_spec--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 // Dump special per-node info
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 void BoolNode::dump_spec(outputStream *st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 st->print("[");
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 _test.dump_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 st->print("]");
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1361
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 //------------------------------is_counted_loop_exit_test--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 // Returns true if node is used by a counted loop node.
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 bool BoolNode::is_counted_loop_exit_test() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 Node* use = fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 if (use->is_CountedLoopEnd()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1373
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 // Compute sqrt
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 const Type *SqrtDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 double d = t1->getd();
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 if( d < 0.0 ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 return TypeD::make( sqrt( d ) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1385
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 // Compute cos
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 const Type *CosDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1394 return TypeD::make( StubRoutines::intrinsic_cos( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1396
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 // Compute sin
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 const Type *SinDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1405 return TypeD::make( StubRoutines::intrinsic_sin( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1407
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 // Compute tan
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 const Type *TanDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1416 return TypeD::make( StubRoutines::intrinsic_tan( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1418
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 // Compute log
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 const Type *LogDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1427 return TypeD::make( StubRoutines::intrinsic_log( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1429
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 // Compute log10
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 const Type *Log10DNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1438 return TypeD::make( StubRoutines::intrinsic_log10( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1440
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 // Compute exp
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 const Type *ExpDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 double d = t1->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1449 return TypeD::make( StubRoutines::intrinsic_exp( d ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1451
a61af66fc99e Initial load
duke
parents:
diff changeset
1452
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 //------------------------------Value------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 // Compute pow
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 const Type *PowDNode::Value( PhaseTransform *phase ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 const Type *t1 = phase->type( in(1) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 if( t1 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 if( t1->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 const Type *t2 = phase->type( in(2) );
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 if( t2 == Type::TOP ) return Type::TOP;
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 if( t2->base() != Type::DoubleCon ) return Type::DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 double d1 = t1->getd();
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 double d2 = t2->getd();
1174
ddb7834449d0 6849984: Value methods for platform dependent math functions constant fold incorrectly
never
parents: 844
diff changeset
1465 return TypeD::make( StubRoutines::intrinsic_pow( d1, d2 ) );
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 }