src/share/vm/opto/addnode.cpp

Fri, 11 Jul 2014 19:51:36 -0400

author
drchase
date
Fri, 11 Jul 2014 19:51:36 -0400
changeset 7161
fc2c88ea11a9
parent 4357
ad5dd04754ee
child 6876
710a3c8b516e
child 9610
f43f77de876a
permissions
-rw-r--r--

8036588: VerifyFieldClosure fails instanceKlass:3133
Summary: Changed deopt live-pointer test to use returns-object instead of live-and-returns-object
Reviewed-by: iveresov, kvn, jrose

duke@435 1 /*
mikael@4153 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "memory/allocation.inline.hpp"
stefank@2314 27 #include "opto/addnode.hpp"
stefank@2314 28 #include "opto/cfgnode.hpp"
stefank@2314 29 #include "opto/connode.hpp"
stefank@2314 30 #include "opto/machnode.hpp"
stefank@2314 31 #include "opto/mulnode.hpp"
stefank@2314 32 #include "opto/phaseX.hpp"
stefank@2314 33 #include "opto/subnode.hpp"
stefank@2314 34
duke@435 35 // Portions of code courtesy of Clifford Click
duke@435 36
duke@435 37 // Classic Add functionality. This covers all the usual 'add' behaviors for
duke@435 38 // an algebraic ring. Add-integer, add-float, add-double, and binary-or are
duke@435 39 // all inherited from this class. The various identity values are supplied
duke@435 40 // by virtual functions.
duke@435 41
duke@435 42
duke@435 43 //=============================================================================
duke@435 44 //------------------------------hash-------------------------------------------
duke@435 45 // Hash function over AddNodes. Needs to be commutative; i.e., I swap
duke@435 46 // (commute) inputs to AddNodes willy-nilly so the hash function must return
duke@435 47 // the same value in the presence of edge swapping.
duke@435 48 uint AddNode::hash() const {
duke@435 49 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode();
duke@435 50 }
duke@435 51
duke@435 52 //------------------------------Identity---------------------------------------
duke@435 53 // If either input is a constant 0, return the other input.
duke@435 54 Node *AddNode::Identity( PhaseTransform *phase ) {
duke@435 55 const Type *zero = add_id(); // The additive identity
duke@435 56 if( phase->type( in(1) )->higher_equal( zero ) ) return in(2);
duke@435 57 if( phase->type( in(2) )->higher_equal( zero ) ) return in(1);
duke@435 58 return this;
duke@435 59 }
duke@435 60
duke@435 61 //------------------------------commute----------------------------------------
duke@435 62 // Commute operands to move loads and constants to the right.
duke@435 63 static bool commute( Node *add, int con_left, int con_right ) {
duke@435 64 Node *in1 = add->in(1);
duke@435 65 Node *in2 = add->in(2);
duke@435 66
duke@435 67 // Convert "1+x" into "x+1".
duke@435 68 // Right is a constant; leave it
duke@435 69 if( con_right ) return false;
duke@435 70 // Left is a constant; move it right.
duke@435 71 if( con_left ) {
duke@435 72 add->swap_edges(1, 2);
duke@435 73 return true;
duke@435 74 }
duke@435 75
duke@435 76 // Convert "Load+x" into "x+Load".
duke@435 77 // Now check for loads
never@534 78 if (in2->is_Load()) {
never@534 79 if (!in1->is_Load()) {
never@534 80 // already x+Load to return
never@534 81 return false;
never@534 82 }
never@534 83 // both are loads, so fall through to sort inputs by idx
never@534 84 } else if( in1->is_Load() ) {
never@534 85 // Left is a Load and Right is not; move it right.
duke@435 86 add->swap_edges(1, 2);
duke@435 87 return true;
duke@435 88 }
duke@435 89
duke@435 90 PhiNode *phi;
duke@435 91 // Check for tight loop increments: Loop-phi of Add of loop-phi
duke@435 92 if( in1->is_Phi() && (phi = in1->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add)
duke@435 93 return false;
duke@435 94 if( in2->is_Phi() && (phi = in2->as_Phi()) && !phi->is_copy() && phi->region()->is_Loop() && phi->in(2)==add){
duke@435 95 add->swap_edges(1, 2);
duke@435 96 return true;
duke@435 97 }
duke@435 98
duke@435 99 // Otherwise, sort inputs (commutativity) to help value numbering.
duke@435 100 if( in1->_idx > in2->_idx ) {
duke@435 101 add->swap_edges(1, 2);
duke@435 102 return true;
duke@435 103 }
duke@435 104 return false;
duke@435 105 }
duke@435 106
duke@435 107 //------------------------------Idealize---------------------------------------
duke@435 108 // If we get here, we assume we are associative!
duke@435 109 Node *AddNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 110 const Type *t1 = phase->type( in(1) );
duke@435 111 const Type *t2 = phase->type( in(2) );
duke@435 112 int con_left = t1->singleton();
duke@435 113 int con_right = t2->singleton();
duke@435 114
duke@435 115 // Check for commutative operation desired
duke@435 116 if( commute(this,con_left,con_right) ) return this;
duke@435 117
duke@435 118 AddNode *progress = NULL; // Progress flag
duke@435 119
duke@435 120 // Convert "(x+1)+2" into "x+(1+2)". If the right input is a
duke@435 121 // constant, and the left input is an add of a constant, flatten the
duke@435 122 // expression tree.
duke@435 123 Node *add1 = in(1);
duke@435 124 Node *add2 = in(2);
duke@435 125 int add1_op = add1->Opcode();
duke@435 126 int this_op = Opcode();
duke@435 127 if( con_right && t2 != Type::TOP && // Right input is a constant?
duke@435 128 add1_op == this_op ) { // Left input is an Add?
duke@435 129
duke@435 130 // Type of left _in right input
duke@435 131 const Type *t12 = phase->type( add1->in(2) );
duke@435 132 if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant?
duke@435 133 // Check for rare case of closed data cycle which can happen inside
duke@435 134 // unreachable loops. In these cases the computation is undefined.
duke@435 135 #ifdef ASSERT
duke@435 136 Node *add11 = add1->in(1);
duke@435 137 int add11_op = add11->Opcode();
duke@435 138 if( (add1 == add1->in(1))
duke@435 139 || (add11_op == this_op && add11->in(1) == add1) ) {
duke@435 140 assert(false, "dead loop in AddNode::Ideal");
duke@435 141 }
duke@435 142 #endif
duke@435 143 // The Add of the flattened expression
duke@435 144 Node *x1 = add1->in(1);
duke@435 145 Node *x2 = phase->makecon( add1->as_Add()->add_ring( t2, t12 ));
duke@435 146 PhaseIterGVN *igvn = phase->is_IterGVN();
duke@435 147 if( igvn ) {
duke@435 148 set_req_X(2,x2,igvn);
duke@435 149 set_req_X(1,x1,igvn);
duke@435 150 } else {
duke@435 151 set_req(2,x2);
duke@435 152 set_req(1,x1);
duke@435 153 }
duke@435 154 progress = this; // Made progress
duke@435 155 add1 = in(1);
duke@435 156 add1_op = add1->Opcode();
duke@435 157 }
duke@435 158 }
duke@435 159
duke@435 160 // Convert "(x+1)+y" into "(x+y)+1". Push constants down the expression tree.
duke@435 161 if( add1_op == this_op && !con_right ) {
duke@435 162 Node *a12 = add1->in(2);
duke@435 163 const Type *t12 = phase->type( a12 );
kvn@835 164 if( t12->singleton() && t12 != Type::TOP && (add1 != add1->in(1)) &&
kvn@835 165 !(add1->in(1)->is_Phi() && add1->in(1)->as_Phi()->is_tripcount()) ) {
kvn@755 166 assert(add1->in(1) != this, "dead loop in AddNode::Ideal");
duke@435 167 add2 = add1->clone();
duke@435 168 add2->set_req(2, in(2));
duke@435 169 add2 = phase->transform(add2);
duke@435 170 set_req(1, add2);
duke@435 171 set_req(2, a12);
duke@435 172 progress = this;
duke@435 173 add2 = a12;
duke@435 174 }
duke@435 175 }
duke@435 176
duke@435 177 // Convert "x+(y+1)" into "(x+y)+1". Push constants down the expression tree.
duke@435 178 int add2_op = add2->Opcode();
duke@435 179 if( add2_op == this_op && !con_left ) {
duke@435 180 Node *a22 = add2->in(2);
duke@435 181 const Type *t22 = phase->type( a22 );
kvn@835 182 if( t22->singleton() && t22 != Type::TOP && (add2 != add2->in(1)) &&
kvn@835 183 !(add2->in(1)->is_Phi() && add2->in(1)->as_Phi()->is_tripcount()) ) {
kvn@755 184 assert(add2->in(1) != this, "dead loop in AddNode::Ideal");
duke@435 185 Node *addx = add2->clone();
duke@435 186 addx->set_req(1, in(1));
duke@435 187 addx->set_req(2, add2->in(1));
duke@435 188 addx = phase->transform(addx);
duke@435 189 set_req(1, addx);
duke@435 190 set_req(2, a22);
duke@435 191 progress = this;
roland@4357 192 PhaseIterGVN *igvn = phase->is_IterGVN();
roland@4357 193 if (add2->outcnt() == 0 && igvn) {
roland@4357 194 // add disconnected.
roland@4357 195 igvn->_worklist.push(add2);
roland@4357 196 }
duke@435 197 }
duke@435 198 }
duke@435 199
duke@435 200 return progress;
duke@435 201 }
duke@435 202
duke@435 203 //------------------------------Value-----------------------------------------
duke@435 204 // An add node sums it's two _in. If one input is an RSD, we must mixin
duke@435 205 // the other input's symbols.
duke@435 206 const Type *AddNode::Value( PhaseTransform *phase ) const {
duke@435 207 // Either input is TOP ==> the result is TOP
duke@435 208 const Type *t1 = phase->type( in(1) );
duke@435 209 const Type *t2 = phase->type( in(2) );
duke@435 210 if( t1 == Type::TOP ) return Type::TOP;
duke@435 211 if( t2 == Type::TOP ) return Type::TOP;
duke@435 212
duke@435 213 // Either input is BOTTOM ==> the result is the local BOTTOM
duke@435 214 const Type *bot = bottom_type();
duke@435 215 if( (t1 == bot) || (t2 == bot) ||
duke@435 216 (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) )
duke@435 217 return bot;
duke@435 218
duke@435 219 // Check for an addition involving the additive identity
duke@435 220 const Type *tadd = add_of_identity( t1, t2 );
duke@435 221 if( tadd ) return tadd;
duke@435 222
duke@435 223 return add_ring(t1,t2); // Local flavor of type addition
duke@435 224 }
duke@435 225
duke@435 226 //------------------------------add_identity-----------------------------------
duke@435 227 // Check for addition of the identity
duke@435 228 const Type *AddNode::add_of_identity( const Type *t1, const Type *t2 ) const {
duke@435 229 const Type *zero = add_id(); // The additive identity
duke@435 230 if( t1->higher_equal( zero ) ) return t2;
duke@435 231 if( t2->higher_equal( zero ) ) return t1;
duke@435 232
duke@435 233 return NULL;
duke@435 234 }
duke@435 235
duke@435 236
duke@435 237 //=============================================================================
duke@435 238 //------------------------------Idealize---------------------------------------
duke@435 239 Node *AddINode::Ideal(PhaseGVN *phase, bool can_reshape) {
kvn@835 240 Node* in1 = in(1);
kvn@835 241 Node* in2 = in(2);
kvn@835 242 int op1 = in1->Opcode();
kvn@835 243 int op2 = in2->Opcode();
duke@435 244 // Fold (con1-x)+con2 into (con1+con2)-x
kvn@835 245 if ( op1 == Op_AddI && op2 == Op_SubI ) {
kvn@835 246 // Swap edges to try optimizations below
kvn@835 247 in1 = in2;
kvn@835 248 in2 = in(1);
kvn@835 249 op1 = op2;
kvn@835 250 op2 = in2->Opcode();
kvn@835 251 }
duke@435 252 if( op1 == Op_SubI ) {
kvn@835 253 const Type *t_sub1 = phase->type( in1->in(1) );
kvn@835 254 const Type *t_2 = phase->type( in2 );
duke@435 255 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
kvn@4115 256 return new (phase->C) SubINode(phase->makecon( add_ring( t_sub1, t_2 ) ),
kvn@835 257 in1->in(2) );
duke@435 258 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
duke@435 259 if( op2 == Op_SubI ) {
duke@435 260 // Check for dead cycle: d = (a-b)+(c-d)
kvn@835 261 assert( in1->in(2) != this && in2->in(2) != this,
duke@435 262 "dead loop in AddINode::Ideal" );
kvn@4115 263 Node *sub = new (phase->C) SubINode(NULL, NULL);
kvn@4115 264 sub->init_req(1, phase->transform(new (phase->C) AddINode(in1->in(1), in2->in(1) ) ));
kvn@4115 265 sub->init_req(2, phase->transform(new (phase->C) AddINode(in1->in(2), in2->in(2) ) ));
duke@435 266 return sub;
duke@435 267 }
kvn@835 268 // Convert "(a-b)+(b+c)" into "(a+c)"
kvn@835 269 if( op2 == Op_AddI && in1->in(2) == in2->in(1) ) {
kvn@835 270 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
kvn@4115 271 return new (phase->C) AddINode(in1->in(1), in2->in(2));
kvn@835 272 }
kvn@835 273 // Convert "(a-b)+(c+b)" into "(a+c)"
kvn@835 274 if( op2 == Op_AddI && in1->in(2) == in2->in(2) ) {
kvn@835 275 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
kvn@4115 276 return new (phase->C) AddINode(in1->in(1), in2->in(1));
kvn@835 277 }
kvn@835 278 // Convert "(a-b)+(b-c)" into "(a-c)"
kvn@835 279 if( op2 == Op_SubI && in1->in(2) == in2->in(1) ) {
kvn@835 280 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddINode::Ideal");
kvn@4115 281 return new (phase->C) SubINode(in1->in(1), in2->in(2));
kvn@835 282 }
kvn@835 283 // Convert "(a-b)+(c-a)" into "(c-b)"
kvn@835 284 if( op2 == Op_SubI && in1->in(1) == in2->in(2) ) {
kvn@835 285 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddINode::Ideal");
kvn@4115 286 return new (phase->C) SubINode(in2->in(1), in1->in(2));
kvn@835 287 }
duke@435 288 }
duke@435 289
duke@435 290 // Convert "x+(0-y)" into "(x-y)"
kvn@835 291 if( op2 == Op_SubI && phase->type(in2->in(1)) == TypeInt::ZERO )
kvn@4115 292 return new (phase->C) SubINode(in1, in2->in(2) );
duke@435 293
duke@435 294 // Convert "(0-y)+x" into "(x-y)"
kvn@835 295 if( op1 == Op_SubI && phase->type(in1->in(1)) == TypeInt::ZERO )
kvn@4115 296 return new (phase->C) SubINode( in2, in1->in(2) );
duke@435 297
duke@435 298 // Convert (x>>>z)+y into (x+(y<<z))>>>z for small constant z and y.
duke@435 299 // Helps with array allocation math constant folding
duke@435 300 // See 4790063:
duke@435 301 // Unrestricted transformation is unsafe for some runtime values of 'x'
duke@435 302 // ( x == 0, z == 1, y == -1 ) fails
duke@435 303 // ( x == -5, z == 1, y == 1 ) fails
duke@435 304 // Transform works for small z and small negative y when the addition
duke@435 305 // (x + (y << z)) does not cross zero.
duke@435 306 // Implement support for negative y and (x >= -(y << z))
duke@435 307 // Have not observed cases where type information exists to support
duke@435 308 // positive y and (x <= -(y << z))
duke@435 309 if( op1 == Op_URShiftI && op2 == Op_ConI &&
kvn@835 310 in1->in(2)->Opcode() == Op_ConI ) {
kvn@835 311 jint z = phase->type( in1->in(2) )->is_int()->get_con() & 0x1f; // only least significant 5 bits matter
kvn@835 312 jint y = phase->type( in2 )->is_int()->get_con();
duke@435 313
duke@435 314 if( z < 5 && -5 < y && y < 0 ) {
kvn@835 315 const Type *t_in11 = phase->type(in1->in(1));
duke@435 316 if( t_in11 != Type::TOP && (t_in11->is_int()->_lo >= -(y << z)) ) {
kvn@4115 317 Node *a = phase->transform( new (phase->C) AddINode( in1->in(1), phase->intcon(y<<z) ) );
kvn@4115 318 return new (phase->C) URShiftINode( a, in1->in(2) );
duke@435 319 }
duke@435 320 }
duke@435 321 }
duke@435 322
duke@435 323 return AddNode::Ideal(phase, can_reshape);
duke@435 324 }
duke@435 325
duke@435 326
duke@435 327 //------------------------------Identity---------------------------------------
duke@435 328 // Fold (x-y)+y OR y+(x-y) into x
duke@435 329 Node *AddINode::Identity( PhaseTransform *phase ) {
duke@435 330 if( in(1)->Opcode() == Op_SubI && phase->eqv(in(1)->in(2),in(2)) ) {
duke@435 331 return in(1)->in(1);
duke@435 332 }
duke@435 333 else if( in(2)->Opcode() == Op_SubI && phase->eqv(in(2)->in(2),in(1)) ) {
duke@435 334 return in(2)->in(1);
duke@435 335 }
duke@435 336 return AddNode::Identity(phase);
duke@435 337 }
duke@435 338
duke@435 339
duke@435 340 //------------------------------add_ring---------------------------------------
duke@435 341 // Supplied function returns the sum of the inputs. Guaranteed never
duke@435 342 // to be passed a TOP or BOTTOM type, these are filtered out by
duke@435 343 // pre-check.
duke@435 344 const Type *AddINode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 345 const TypeInt *r0 = t0->is_int(); // Handy access
duke@435 346 const TypeInt *r1 = t1->is_int();
duke@435 347 int lo = r0->_lo + r1->_lo;
duke@435 348 int hi = r0->_hi + r1->_hi;
duke@435 349 if( !(r0->is_con() && r1->is_con()) ) {
duke@435 350 // Not both constants, compute approximate result
duke@435 351 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
duke@435 352 lo = min_jint; hi = max_jint; // Underflow on the low side
duke@435 353 }
duke@435 354 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
duke@435 355 lo = min_jint; hi = max_jint; // Overflow on the high side
duke@435 356 }
duke@435 357 if( lo > hi ) { // Handle overflow
duke@435 358 lo = min_jint; hi = max_jint;
duke@435 359 }
duke@435 360 } else {
duke@435 361 // both constants, compute precise result using 'lo' and 'hi'
duke@435 362 // Semantics define overflow and underflow for integer addition
duke@435 363 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
duke@435 364 }
duke@435 365 return TypeInt::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
duke@435 366 }
duke@435 367
duke@435 368
duke@435 369 //=============================================================================
duke@435 370 //------------------------------Idealize---------------------------------------
duke@435 371 Node *AddLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
kvn@835 372 Node* in1 = in(1);
kvn@835 373 Node* in2 = in(2);
kvn@835 374 int op1 = in1->Opcode();
kvn@835 375 int op2 = in2->Opcode();
kvn@835 376 // Fold (con1-x)+con2 into (con1+con2)-x
kvn@835 377 if ( op1 == Op_AddL && op2 == Op_SubL ) {
kvn@835 378 // Swap edges to try optimizations below
kvn@835 379 in1 = in2;
kvn@835 380 in2 = in(1);
kvn@835 381 op1 = op2;
kvn@835 382 op2 = in2->Opcode();
kvn@835 383 }
duke@435 384 // Fold (con1-x)+con2 into (con1+con2)-x
duke@435 385 if( op1 == Op_SubL ) {
kvn@835 386 const Type *t_sub1 = phase->type( in1->in(1) );
kvn@835 387 const Type *t_2 = phase->type( in2 );
duke@435 388 if( t_sub1->singleton() && t_2->singleton() && t_sub1 != Type::TOP && t_2 != Type::TOP )
kvn@4115 389 return new (phase->C) SubLNode(phase->makecon( add_ring( t_sub1, t_2 ) ),
kvn@835 390 in1->in(2) );
duke@435 391 // Convert "(a-b)+(c-d)" into "(a+c)-(b+d)"
duke@435 392 if( op2 == Op_SubL ) {
duke@435 393 // Check for dead cycle: d = (a-b)+(c-d)
kvn@835 394 assert( in1->in(2) != this && in2->in(2) != this,
duke@435 395 "dead loop in AddLNode::Ideal" );
kvn@4115 396 Node *sub = new (phase->C) SubLNode(NULL, NULL);
kvn@4115 397 sub->init_req(1, phase->transform(new (phase->C) AddLNode(in1->in(1), in2->in(1) ) ));
kvn@4115 398 sub->init_req(2, phase->transform(new (phase->C) AddLNode(in1->in(2), in2->in(2) ) ));
duke@435 399 return sub;
duke@435 400 }
kvn@835 401 // Convert "(a-b)+(b+c)" into "(a+c)"
kvn@835 402 if( op2 == Op_AddL && in1->in(2) == in2->in(1) ) {
kvn@835 403 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
kvn@4115 404 return new (phase->C) AddLNode(in1->in(1), in2->in(2));
kvn@835 405 }
kvn@835 406 // Convert "(a-b)+(c+b)" into "(a+c)"
kvn@835 407 if( op2 == Op_AddL && in1->in(2) == in2->in(2) ) {
kvn@835 408 assert(in1->in(1) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
kvn@4115 409 return new (phase->C) AddLNode(in1->in(1), in2->in(1));
kvn@835 410 }
kvn@835 411 // Convert "(a-b)+(b-c)" into "(a-c)"
kvn@835 412 if( op2 == Op_SubL && in1->in(2) == in2->in(1) ) {
kvn@835 413 assert(in1->in(1) != this && in2->in(2) != this,"dead loop in AddLNode::Ideal");
kvn@4115 414 return new (phase->C) SubLNode(in1->in(1), in2->in(2));
kvn@835 415 }
kvn@835 416 // Convert "(a-b)+(c-a)" into "(c-b)"
kvn@835 417 if( op2 == Op_SubL && in1->in(1) == in1->in(2) ) {
kvn@835 418 assert(in1->in(2) != this && in2->in(1) != this,"dead loop in AddLNode::Ideal");
kvn@4115 419 return new (phase->C) SubLNode(in2->in(1), in1->in(2));
kvn@835 420 }
duke@435 421 }
duke@435 422
duke@435 423 // Convert "x+(0-y)" into "(x-y)"
kvn@835 424 if( op2 == Op_SubL && phase->type(in2->in(1)) == TypeLong::ZERO )
kvn@4115 425 return new (phase->C) SubLNode( in1, in2->in(2) );
kvn@835 426
kvn@835 427 // Convert "(0-y)+x" into "(x-y)"
kvn@835 428 if( op1 == Op_SubL && phase->type(in1->in(1)) == TypeInt::ZERO )
kvn@4115 429 return new (phase->C) SubLNode( in2, in1->in(2) );
duke@435 430
duke@435 431 // Convert "X+X+X+X+X...+X+Y" into "k*X+Y" or really convert "X+(X+Y)"
duke@435 432 // into "(X<<1)+Y" and let shift-folding happen.
duke@435 433 if( op2 == Op_AddL &&
kvn@835 434 in2->in(1) == in1 &&
duke@435 435 op1 != Op_ConL &&
duke@435 436 0 ) {
kvn@4115 437 Node *shift = phase->transform(new (phase->C) LShiftLNode(in1,phase->intcon(1)));
kvn@4115 438 return new (phase->C) AddLNode(shift,in2->in(2));
duke@435 439 }
duke@435 440
duke@435 441 return AddNode::Ideal(phase, can_reshape);
duke@435 442 }
duke@435 443
duke@435 444
duke@435 445 //------------------------------Identity---------------------------------------
duke@435 446 // Fold (x-y)+y OR y+(x-y) into x
duke@435 447 Node *AddLNode::Identity( PhaseTransform *phase ) {
duke@435 448 if( in(1)->Opcode() == Op_SubL && phase->eqv(in(1)->in(2),in(2)) ) {
duke@435 449 return in(1)->in(1);
duke@435 450 }
duke@435 451 else if( in(2)->Opcode() == Op_SubL && phase->eqv(in(2)->in(2),in(1)) ) {
duke@435 452 return in(2)->in(1);
duke@435 453 }
duke@435 454 return AddNode::Identity(phase);
duke@435 455 }
duke@435 456
duke@435 457
duke@435 458 //------------------------------add_ring---------------------------------------
duke@435 459 // Supplied function returns the sum of the inputs. Guaranteed never
duke@435 460 // to be passed a TOP or BOTTOM type, these are filtered out by
duke@435 461 // pre-check.
duke@435 462 const Type *AddLNode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 463 const TypeLong *r0 = t0->is_long(); // Handy access
duke@435 464 const TypeLong *r1 = t1->is_long();
duke@435 465 jlong lo = r0->_lo + r1->_lo;
duke@435 466 jlong hi = r0->_hi + r1->_hi;
duke@435 467 if( !(r0->is_con() && r1->is_con()) ) {
duke@435 468 // Not both constants, compute approximate result
duke@435 469 if( (r0->_lo & r1->_lo) < 0 && lo >= 0 ) {
duke@435 470 lo =min_jlong; hi = max_jlong; // Underflow on the low side
duke@435 471 }
duke@435 472 if( (~(r0->_hi | r1->_hi)) < 0 && hi < 0 ) {
duke@435 473 lo = min_jlong; hi = max_jlong; // Overflow on the high side
duke@435 474 }
duke@435 475 if( lo > hi ) { // Handle overflow
duke@435 476 lo = min_jlong; hi = max_jlong;
duke@435 477 }
duke@435 478 } else {
duke@435 479 // both constants, compute precise result using 'lo' and 'hi'
duke@435 480 // Semantics define overflow and underflow for integer addition
duke@435 481 // as expected. In particular: 0x80000000 + 0x80000000 --> 0x0
duke@435 482 }
duke@435 483 return TypeLong::make( lo, hi, MAX2(r0->_widen,r1->_widen) );
duke@435 484 }
duke@435 485
duke@435 486
duke@435 487 //=============================================================================
duke@435 488 //------------------------------add_of_identity--------------------------------
duke@435 489 // Check for addition of the identity
duke@435 490 const Type *AddFNode::add_of_identity( const Type *t1, const Type *t2 ) const {
duke@435 491 // x ADD 0 should return x unless 'x' is a -zero
duke@435 492 //
duke@435 493 // const Type *zero = add_id(); // The additive identity
duke@435 494 // jfloat f1 = t1->getf();
duke@435 495 // jfloat f2 = t2->getf();
duke@435 496 //
duke@435 497 // if( t1->higher_equal( zero ) ) return t2;
duke@435 498 // if( t2->higher_equal( zero ) ) return t1;
duke@435 499
duke@435 500 return NULL;
duke@435 501 }
duke@435 502
duke@435 503 //------------------------------add_ring---------------------------------------
duke@435 504 // Supplied function returns the sum of the inputs.
duke@435 505 // This also type-checks the inputs for sanity. Guaranteed never to
duke@435 506 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
duke@435 507 const Type *AddFNode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 508 // We must be adding 2 float constants.
duke@435 509 return TypeF::make( t0->getf() + t1->getf() );
duke@435 510 }
duke@435 511
duke@435 512 //------------------------------Ideal------------------------------------------
duke@435 513 Node *AddFNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 514 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
duke@435 515 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
duke@435 516 }
duke@435 517
duke@435 518 // Floating point additions are not associative because of boundary conditions (infinity)
duke@435 519 return commute(this,
duke@435 520 phase->type( in(1) )->singleton(),
duke@435 521 phase->type( in(2) )->singleton() ) ? this : NULL;
duke@435 522 }
duke@435 523
duke@435 524
duke@435 525 //=============================================================================
duke@435 526 //------------------------------add_of_identity--------------------------------
duke@435 527 // Check for addition of the identity
duke@435 528 const Type *AddDNode::add_of_identity( const Type *t1, const Type *t2 ) const {
duke@435 529 // x ADD 0 should return x unless 'x' is a -zero
duke@435 530 //
duke@435 531 // const Type *zero = add_id(); // The additive identity
duke@435 532 // jfloat f1 = t1->getf();
duke@435 533 // jfloat f2 = t2->getf();
duke@435 534 //
duke@435 535 // if( t1->higher_equal( zero ) ) return t2;
duke@435 536 // if( t2->higher_equal( zero ) ) return t1;
duke@435 537
duke@435 538 return NULL;
duke@435 539 }
duke@435 540 //------------------------------add_ring---------------------------------------
duke@435 541 // Supplied function returns the sum of the inputs.
duke@435 542 // This also type-checks the inputs for sanity. Guaranteed never to
duke@435 543 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
duke@435 544 const Type *AddDNode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 545 // We must be adding 2 double constants.
duke@435 546 return TypeD::make( t0->getd() + t1->getd() );
duke@435 547 }
duke@435 548
duke@435 549 //------------------------------Ideal------------------------------------------
duke@435 550 Node *AddDNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 551 if( IdealizedNumerics && !phase->C->method()->is_strict() ) {
duke@435 552 return AddNode::Ideal(phase, can_reshape); // commutative and associative transforms
duke@435 553 }
duke@435 554
duke@435 555 // Floating point additions are not associative because of boundary conditions (infinity)
duke@435 556 return commute(this,
duke@435 557 phase->type( in(1) )->singleton(),
duke@435 558 phase->type( in(2) )->singleton() ) ? this : NULL;
duke@435 559 }
duke@435 560
duke@435 561
duke@435 562 //=============================================================================
duke@435 563 //------------------------------Identity---------------------------------------
duke@435 564 // If one input is a constant 0, return the other input.
duke@435 565 Node *AddPNode::Identity( PhaseTransform *phase ) {
duke@435 566 return ( phase->type( in(Offset) )->higher_equal( TypeX_ZERO ) ) ? in(Address) : this;
duke@435 567 }
duke@435 568
duke@435 569 //------------------------------Idealize---------------------------------------
duke@435 570 Node *AddPNode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 571 // Bail out if dead inputs
duke@435 572 if( phase->type( in(Address) ) == Type::TOP ) return NULL;
duke@435 573
duke@435 574 // If the left input is an add of a constant, flatten the expression tree.
duke@435 575 const Node *n = in(Address);
duke@435 576 if (n->is_AddP() && n->in(Base) == in(Base)) {
duke@435 577 const AddPNode *addp = n->as_AddP(); // Left input is an AddP
duke@435 578 assert( !addp->in(Address)->is_AddP() ||
duke@435 579 addp->in(Address)->as_AddP() != addp,
duke@435 580 "dead loop in AddPNode::Ideal" );
duke@435 581 // Type of left input's right input
duke@435 582 const Type *t = phase->type( addp->in(Offset) );
duke@435 583 if( t == Type::TOP ) return NULL;
duke@435 584 const TypeX *t12 = t->is_intptr_t();
duke@435 585 if( t12->is_con() ) { // Left input is an add of a constant?
duke@435 586 // If the right input is a constant, combine constants
duke@435 587 const Type *temp_t2 = phase->type( in(Offset) );
duke@435 588 if( temp_t2 == Type::TOP ) return NULL;
duke@435 589 const TypeX *t2 = temp_t2->is_intptr_t();
kvn@467 590 Node* address;
kvn@467 591 Node* offset;
duke@435 592 if( t2->is_con() ) {
duke@435 593 // The Add of the flattened expression
kvn@467 594 address = addp->in(Address);
kvn@467 595 offset = phase->MakeConX(t2->get_con() + t12->get_con());
kvn@467 596 } else {
kvn@467 597 // Else move the constant to the right. ((A+con)+B) into ((A+B)+con)
kvn@4115 598 address = phase->transform(new (phase->C) AddPNode(in(Base),addp->in(Address),in(Offset)));
kvn@467 599 offset = addp->in(Offset);
duke@435 600 }
kvn@467 601 PhaseIterGVN *igvn = phase->is_IterGVN();
kvn@467 602 if( igvn ) {
kvn@467 603 set_req_X(Address,address,igvn);
kvn@467 604 set_req_X(Offset,offset,igvn);
kvn@467 605 } else {
kvn@467 606 set_req(Address,address);
kvn@467 607 set_req(Offset,offset);
kvn@467 608 }
duke@435 609 return this;
duke@435 610 }
duke@435 611 }
duke@435 612
duke@435 613 // Raw pointers?
duke@435 614 if( in(Base)->bottom_type() == Type::TOP ) {
duke@435 615 // If this is a NULL+long form (from unsafe accesses), switch to a rawptr.
duke@435 616 if (phase->type(in(Address)) == TypePtr::NULL_PTR) {
duke@435 617 Node* offset = in(Offset);
kvn@4115 618 return new (phase->C) CastX2PNode(offset);
duke@435 619 }
duke@435 620 }
duke@435 621
duke@435 622 // If the right is an add of a constant, push the offset down.
duke@435 623 // Convert: (ptr + (offset+con)) into (ptr+offset)+con.
duke@435 624 // The idea is to merge array_base+scaled_index groups together,
duke@435 625 // and only have different constant offsets from the same base.
duke@435 626 const Node *add = in(Offset);
duke@435 627 if( add->Opcode() == Op_AddX && add->in(1) != add ) {
duke@435 628 const Type *t22 = phase->type( add->in(2) );
duke@435 629 if( t22->singleton() && (t22 != Type::TOP) ) { // Right input is an add of a constant?
kvn@4115 630 set_req(Address, phase->transform(new (phase->C) AddPNode(in(Base),in(Address),add->in(1))));
duke@435 631 set_req(Offset, add->in(2));
roland@4357 632 PhaseIterGVN *igvn = phase->is_IterGVN();
roland@4357 633 if (add->outcnt() == 0 && igvn) {
roland@4357 634 // add disconnected.
roland@4357 635 igvn->_worklist.push((Node*)add);
roland@4357 636 }
duke@435 637 return this; // Made progress
duke@435 638 }
duke@435 639 }
duke@435 640
duke@435 641 return NULL; // No progress
duke@435 642 }
duke@435 643
duke@435 644 //------------------------------bottom_type------------------------------------
duke@435 645 // Bottom-type is the pointer-type with unknown offset.
duke@435 646 const Type *AddPNode::bottom_type() const {
duke@435 647 if (in(Address) == NULL) return TypePtr::BOTTOM;
duke@435 648 const TypePtr *tp = in(Address)->bottom_type()->isa_ptr();
duke@435 649 if( !tp ) return Type::TOP; // TOP input means TOP output
duke@435 650 assert( in(Offset)->Opcode() != Op_ConP, "" );
duke@435 651 const Type *t = in(Offset)->bottom_type();
duke@435 652 if( t == Type::TOP )
duke@435 653 return tp->add_offset(Type::OffsetTop);
duke@435 654 const TypeX *tx = t->is_intptr_t();
duke@435 655 intptr_t txoffset = Type::OffsetBot;
duke@435 656 if (tx->is_con()) { // Left input is an add of a constant?
duke@435 657 txoffset = tx->get_con();
duke@435 658 }
duke@435 659 return tp->add_offset(txoffset);
duke@435 660 }
duke@435 661
duke@435 662 //------------------------------Value------------------------------------------
duke@435 663 const Type *AddPNode::Value( PhaseTransform *phase ) const {
duke@435 664 // Either input is TOP ==> the result is TOP
duke@435 665 const Type *t1 = phase->type( in(Address) );
duke@435 666 const Type *t2 = phase->type( in(Offset) );
duke@435 667 if( t1 == Type::TOP ) return Type::TOP;
duke@435 668 if( t2 == Type::TOP ) return Type::TOP;
duke@435 669
duke@435 670 // Left input is a pointer
duke@435 671 const TypePtr *p1 = t1->isa_ptr();
duke@435 672 // Right input is an int
duke@435 673 const TypeX *p2 = t2->is_intptr_t();
duke@435 674 // Add 'em
duke@435 675 intptr_t p2offset = Type::OffsetBot;
duke@435 676 if (p2->is_con()) { // Left input is an add of a constant?
duke@435 677 p2offset = p2->get_con();
duke@435 678 }
duke@435 679 return p1->add_offset(p2offset);
duke@435 680 }
duke@435 681
duke@435 682 //------------------------Ideal_base_and_offset--------------------------------
duke@435 683 // Split an oop pointer into a base and offset.
duke@435 684 // (The offset might be Type::OffsetBot in the case of an array.)
duke@435 685 // Return the base, or NULL if failure.
duke@435 686 Node* AddPNode::Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,
duke@435 687 // second return value:
duke@435 688 intptr_t& offset) {
duke@435 689 if (ptr->is_AddP()) {
duke@435 690 Node* base = ptr->in(AddPNode::Base);
duke@435 691 Node* addr = ptr->in(AddPNode::Address);
duke@435 692 Node* offs = ptr->in(AddPNode::Offset);
duke@435 693 if (base == addr || base->is_top()) {
duke@435 694 offset = phase->find_intptr_t_con(offs, Type::OffsetBot);
duke@435 695 if (offset != Type::OffsetBot) {
duke@435 696 return addr;
duke@435 697 }
duke@435 698 }
duke@435 699 }
duke@435 700 offset = Type::OffsetBot;
duke@435 701 return NULL;
duke@435 702 }
duke@435 703
never@452 704 //------------------------------unpack_offsets----------------------------------
never@452 705 // Collect the AddP offset values into the elements array, giving up
never@452 706 // if there are more than length.
never@452 707 int AddPNode::unpack_offsets(Node* elements[], int length) {
never@452 708 int count = 0;
never@452 709 Node* addr = this;
never@452 710 Node* base = addr->in(AddPNode::Base);
never@452 711 while (addr->is_AddP()) {
never@452 712 if (addr->in(AddPNode::Base) != base) {
never@452 713 // give up
never@452 714 return -1;
never@452 715 }
never@452 716 elements[count++] = addr->in(AddPNode::Offset);
never@452 717 if (count == length) {
never@452 718 // give up
never@452 719 return -1;
never@452 720 }
never@452 721 addr = addr->in(AddPNode::Address);
never@452 722 }
never@2118 723 if (addr != base) {
never@2118 724 return -1;
never@2118 725 }
never@452 726 return count;
never@452 727 }
never@452 728
duke@435 729 //------------------------------match_edge-------------------------------------
duke@435 730 // Do we Match on this edge index or not? Do not match base pointer edge
duke@435 731 uint AddPNode::match_edge(uint idx) const {
duke@435 732 return idx > Base;
duke@435 733 }
duke@435 734
duke@435 735 //=============================================================================
duke@435 736 //------------------------------Identity---------------------------------------
duke@435 737 Node *OrINode::Identity( PhaseTransform *phase ) {
duke@435 738 // x | x => x
duke@435 739 if (phase->eqv(in(1), in(2))) {
duke@435 740 return in(1);
duke@435 741 }
duke@435 742
duke@435 743 return AddNode::Identity(phase);
duke@435 744 }
duke@435 745
duke@435 746 //------------------------------add_ring---------------------------------------
duke@435 747 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
duke@435 748 // the logical operations the ring's ADD is really a logical OR function.
duke@435 749 // This also type-checks the inputs for sanity. Guaranteed never to
duke@435 750 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
duke@435 751 const Type *OrINode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 752 const TypeInt *r0 = t0->is_int(); // Handy access
duke@435 753 const TypeInt *r1 = t1->is_int();
duke@435 754
duke@435 755 // If both args are bool, can figure out better types
duke@435 756 if ( r0 == TypeInt::BOOL ) {
duke@435 757 if ( r1 == TypeInt::ONE) {
duke@435 758 return TypeInt::ONE;
duke@435 759 } else if ( r1 == TypeInt::BOOL ) {
duke@435 760 return TypeInt::BOOL;
duke@435 761 }
duke@435 762 } else if ( r0 == TypeInt::ONE ) {
duke@435 763 if ( r1 == TypeInt::BOOL ) {
duke@435 764 return TypeInt::ONE;
duke@435 765 }
duke@435 766 }
duke@435 767
duke@435 768 // If either input is not a constant, just return all integers.
duke@435 769 if( !r0->is_con() || !r1->is_con() )
duke@435 770 return TypeInt::INT; // Any integer, but still no symbols.
duke@435 771
duke@435 772 // Otherwise just OR them bits.
duke@435 773 return TypeInt::make( r0->get_con() | r1->get_con() );
duke@435 774 }
duke@435 775
duke@435 776 //=============================================================================
duke@435 777 //------------------------------Identity---------------------------------------
duke@435 778 Node *OrLNode::Identity( PhaseTransform *phase ) {
duke@435 779 // x | x => x
duke@435 780 if (phase->eqv(in(1), in(2))) {
duke@435 781 return in(1);
duke@435 782 }
duke@435 783
duke@435 784 return AddNode::Identity(phase);
duke@435 785 }
duke@435 786
duke@435 787 //------------------------------add_ring---------------------------------------
duke@435 788 const Type *OrLNode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 789 const TypeLong *r0 = t0->is_long(); // Handy access
duke@435 790 const TypeLong *r1 = t1->is_long();
duke@435 791
duke@435 792 // If either input is not a constant, just return all integers.
duke@435 793 if( !r0->is_con() || !r1->is_con() )
duke@435 794 return TypeLong::LONG; // Any integer, but still no symbols.
duke@435 795
duke@435 796 // Otherwise just OR them bits.
duke@435 797 return TypeLong::make( r0->get_con() | r1->get_con() );
duke@435 798 }
duke@435 799
duke@435 800 //=============================================================================
duke@435 801 //------------------------------add_ring---------------------------------------
duke@435 802 // Supplied function returns the sum of the inputs IN THE CURRENT RING. For
duke@435 803 // the logical operations the ring's ADD is really a logical OR function.
duke@435 804 // This also type-checks the inputs for sanity. Guaranteed never to
duke@435 805 // be passed a TOP or BOTTOM type, these are filtered out by pre-check.
duke@435 806 const Type *XorINode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 807 const TypeInt *r0 = t0->is_int(); // Handy access
duke@435 808 const TypeInt *r1 = t1->is_int();
duke@435 809
duke@435 810 // Complementing a boolean?
duke@435 811 if( r0 == TypeInt::BOOL && ( r1 == TypeInt::ONE
duke@435 812 || r1 == TypeInt::BOOL))
duke@435 813 return TypeInt::BOOL;
duke@435 814
duke@435 815 if( !r0->is_con() || !r1->is_con() ) // Not constants
duke@435 816 return TypeInt::INT; // Any integer, but still no symbols.
duke@435 817
duke@435 818 // Otherwise just XOR them bits.
duke@435 819 return TypeInt::make( r0->get_con() ^ r1->get_con() );
duke@435 820 }
duke@435 821
duke@435 822 //=============================================================================
duke@435 823 //------------------------------add_ring---------------------------------------
duke@435 824 const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 825 const TypeLong *r0 = t0->is_long(); // Handy access
duke@435 826 const TypeLong *r1 = t1->is_long();
duke@435 827
duke@435 828 // If either input is not a constant, just return all integers.
duke@435 829 if( !r0->is_con() || !r1->is_con() )
duke@435 830 return TypeLong::LONG; // Any integer, but still no symbols.
duke@435 831
duke@435 832 // Otherwise just OR them bits.
duke@435 833 return TypeLong::make( r0->get_con() ^ r1->get_con() );
duke@435 834 }
duke@435 835
duke@435 836 //=============================================================================
duke@435 837 //------------------------------add_ring---------------------------------------
duke@435 838 // Supplied function returns the sum of the inputs.
duke@435 839 const Type *MaxINode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 840 const TypeInt *r0 = t0->is_int(); // Handy access
duke@435 841 const TypeInt *r1 = t1->is_int();
duke@435 842
duke@435 843 // Otherwise just MAX them bits.
duke@435 844 return TypeInt::make( MAX2(r0->_lo,r1->_lo), MAX2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
duke@435 845 }
duke@435 846
duke@435 847 //=============================================================================
duke@435 848 //------------------------------Idealize---------------------------------------
duke@435 849 // MINs show up in range-check loop limit calculations. Look for
duke@435 850 // "MIN2(x+c0,MIN2(y,x+c1))". Pick the smaller constant: "MIN2(x+c0,y)"
duke@435 851 Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
duke@435 852 Node *progress = NULL;
duke@435 853 // Force a right-spline graph
duke@435 854 Node *l = in(1);
duke@435 855 Node *r = in(2);
duke@435 856 // Transform MinI1( MinI2(a,b), c) into MinI1( a, MinI2(b,c) )
duke@435 857 // to force a right-spline graph for the rest of MinINode::Ideal().
duke@435 858 if( l->Opcode() == Op_MinI ) {
duke@435 859 assert( l != l->in(1), "dead loop in MinINode::Ideal" );
kvn@4115 860 r = phase->transform(new (phase->C) MinINode(l->in(2),r));
duke@435 861 l = l->in(1);
duke@435 862 set_req(1, l);
duke@435 863 set_req(2, r);
duke@435 864 return this;
duke@435 865 }
duke@435 866
duke@435 867 // Get left input & constant
duke@435 868 Node *x = l;
duke@435 869 int x_off = 0;
duke@435 870 if( x->Opcode() == Op_AddI && // Check for "x+c0" and collect constant
duke@435 871 x->in(2)->is_Con() ) {
duke@435 872 const Type *t = x->in(2)->bottom_type();
duke@435 873 if( t == Type::TOP ) return NULL; // No progress
duke@435 874 x_off = t->is_int()->get_con();
duke@435 875 x = x->in(1);
duke@435 876 }
duke@435 877
duke@435 878 // Scan a right-spline-tree for MINs
duke@435 879 Node *y = r;
duke@435 880 int y_off = 0;
duke@435 881 // Check final part of MIN tree
duke@435 882 if( y->Opcode() == Op_AddI && // Check for "y+c1" and collect constant
duke@435 883 y->in(2)->is_Con() ) {
duke@435 884 const Type *t = y->in(2)->bottom_type();
duke@435 885 if( t == Type::TOP ) return NULL; // No progress
duke@435 886 y_off = t->is_int()->get_con();
duke@435 887 y = y->in(1);
duke@435 888 }
duke@435 889 if( x->_idx > y->_idx && r->Opcode() != Op_MinI ) {
duke@435 890 swap_edges(1, 2);
duke@435 891 return this;
duke@435 892 }
duke@435 893
duke@435 894
duke@435 895 if( r->Opcode() == Op_MinI ) {
duke@435 896 assert( r != r->in(2), "dead loop in MinINode::Ideal" );
duke@435 897 y = r->in(1);
duke@435 898 // Check final part of MIN tree
duke@435 899 if( y->Opcode() == Op_AddI &&// Check for "y+c1" and collect constant
duke@435 900 y->in(2)->is_Con() ) {
duke@435 901 const Type *t = y->in(2)->bottom_type();
duke@435 902 if( t == Type::TOP ) return NULL; // No progress
duke@435 903 y_off = t->is_int()->get_con();
duke@435 904 y = y->in(1);
duke@435 905 }
duke@435 906
duke@435 907 if( x->_idx > y->_idx )
kvn@4115 908 return new (phase->C) MinINode(r->in(1),phase->transform(new (phase->C) MinINode(l,r->in(2))));
duke@435 909
duke@435 910 // See if covers: MIN2(x+c0,MIN2(y+c1,z))
duke@435 911 if( !phase->eqv(x,y) ) return NULL;
duke@435 912 // If (y == x) transform MIN2(x+c0, MIN2(x+c1,z)) into
duke@435 913 // MIN2(x+c0 or x+c1 which less, z).
kvn@4115 914 return new (phase->C) MinINode(phase->transform(new (phase->C) AddINode(x,phase->intcon(MIN2(x_off,y_off)))),r->in(2));
duke@435 915 } else {
duke@435 916 // See if covers: MIN2(x+c0,y+c1)
duke@435 917 if( !phase->eqv(x,y) ) return NULL;
duke@435 918 // If (y == x) transform MIN2(x+c0,x+c1) into x+c0 or x+c1 which less.
kvn@4115 919 return new (phase->C) AddINode(x,phase->intcon(MIN2(x_off,y_off)));
duke@435 920 }
duke@435 921
duke@435 922 }
duke@435 923
duke@435 924 //------------------------------add_ring---------------------------------------
duke@435 925 // Supplied function returns the sum of the inputs.
duke@435 926 const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
duke@435 927 const TypeInt *r0 = t0->is_int(); // Handy access
duke@435 928 const TypeInt *r1 = t1->is_int();
duke@435 929
duke@435 930 // Otherwise just MIN them bits.
duke@435 931 return TypeInt::make( MIN2(r0->_lo,r1->_lo), MIN2(r0->_hi,r1->_hi), MAX2(r0->_widen,r1->_widen) );
duke@435 932 }

mercurial