src/share/vm/opto/addnode.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 6876
710a3c8b516e
child 9637
eef07cd490d4
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial