| File: | jdk/src/hotspot/share/opto/mulnode.cpp |
| Warning: | line 1042, column 11 Value stored to 'x' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "precompiled.hpp" |
| 26 | #include "memory/allocation.inline.hpp" |
| 27 | #include "opto/addnode.hpp" |
| 28 | #include "opto/connode.hpp" |
| 29 | #include "opto/convertnode.hpp" |
| 30 | #include "opto/memnode.hpp" |
| 31 | #include "opto/mulnode.hpp" |
| 32 | #include "opto/phaseX.hpp" |
| 33 | #include "opto/subnode.hpp" |
| 34 | #include "utilities/powerOfTwo.hpp" |
| 35 | |
| 36 | // Portions of code courtesy of Clifford Click |
| 37 | |
| 38 | |
| 39 | //============================================================================= |
| 40 | //------------------------------hash------------------------------------------- |
| 41 | // Hash function over MulNodes. Needs to be commutative; i.e., I swap |
| 42 | // (commute) inputs to MulNodes willy-nilly so the hash function must return |
| 43 | // the same value in the presence of edge swapping. |
| 44 | uint MulNode::hash() const { |
| 45 | return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode(); |
| 46 | } |
| 47 | |
| 48 | //------------------------------Identity--------------------------------------- |
| 49 | // Multiplying a one preserves the other argument |
| 50 | Node* MulNode::Identity(PhaseGVN* phase) { |
| 51 | const Type *one = mul_id(); // The multiplicative identity |
| 52 | if( phase->type( in(1) )->higher_equal( one ) ) return in(2); |
| 53 | if( phase->type( in(2) )->higher_equal( one ) ) return in(1); |
| 54 | |
| 55 | return this; |
| 56 | } |
| 57 | |
| 58 | //------------------------------Ideal------------------------------------------ |
| 59 | // We also canonicalize the Node, moving constants to the right input, |
| 60 | // and flatten expressions (so that 1+x+2 becomes x+3). |
| 61 | Node *MulNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 62 | Node* in1 = in(1); |
| 63 | Node* in2 = in(2); |
| 64 | Node* progress = NULL__null; // Progress flag |
| 65 | |
| 66 | // This code is used by And nodes too, but some conversions are |
| 67 | // only valid for the actual Mul nodes. |
| 68 | uint op = Opcode(); |
| 69 | bool real_mul = (op == Op_MulI) || (op == Op_MulL) || |
| 70 | (op == Op_MulF) || (op == Op_MulD); |
| 71 | |
| 72 | // Convert "(-a)*(-b)" into "a*b". |
| 73 | if (real_mul && in1->is_Sub() && in2->is_Sub()) { |
| 74 | if (phase->type(in1->in(1))->is_zero_type() && |
| 75 | phase->type(in2->in(1))->is_zero_type()) { |
| 76 | set_req(1, in1->in(2)); |
| 77 | set_req(2, in2->in(2)); |
| 78 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
| 79 | if (igvn) { |
| 80 | igvn->_worklist.push(in1); |
| 81 | igvn->_worklist.push(in2); |
| 82 | } |
| 83 | in1 = in(1); |
| 84 | in2 = in(2); |
| 85 | progress = this; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // convert "max(a,b) * min(a,b)" into "a*b". |
| 90 | if ((in(1)->Opcode() == max_opcode() && in(2)->Opcode() == min_opcode()) |
| 91 | || (in(1)->Opcode() == min_opcode() && in(2)->Opcode() == max_opcode())) { |
| 92 | Node *in11 = in(1)->in(1); |
| 93 | Node *in12 = in(1)->in(2); |
| 94 | |
| 95 | Node *in21 = in(2)->in(1); |
| 96 | Node *in22 = in(2)->in(2); |
| 97 | |
| 98 | if ((in11 == in21 && in12 == in22) || |
| 99 | (in11 == in22 && in12 == in21)) { |
| 100 | set_req(1, in11); |
| 101 | set_req(2, in12); |
| 102 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
| 103 | if (igvn) { |
| 104 | igvn->_worklist.push(in1); |
| 105 | igvn->_worklist.push(in2); |
| 106 | } |
| 107 | in1 = in(1); |
| 108 | in2 = in(2); |
| 109 | progress = this; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | const Type* t1 = phase->type(in1); |
| 114 | const Type* t2 = phase->type(in2); |
| 115 | |
| 116 | // We are OK if right is a constant, or right is a load and |
| 117 | // left is a non-constant. |
| 118 | if( !(t2->singleton() || |
| 119 | (in(2)->is_Load() && !(t1->singleton() || in(1)->is_Load())) ) ) { |
| 120 | if( t1->singleton() || // Left input is a constant? |
| 121 | // Otherwise, sort inputs (commutativity) to help value numbering. |
| 122 | (in(1)->_idx > in(2)->_idx) ) { |
| 123 | swap_edges(1, 2); |
| 124 | const Type *t = t1; |
| 125 | t1 = t2; |
| 126 | t2 = t; |
| 127 | progress = this; // Made progress |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // If the right input is a constant, and the left input is a product of a |
| 132 | // constant, flatten the expression tree. |
| 133 | if( t2->singleton() && // Right input is a constant? |
| 134 | op != Op_MulF && // Float & double cannot reassociate |
| 135 | op != Op_MulD ) { |
| 136 | if( t2 == Type::TOP ) return NULL__null; |
| 137 | Node *mul1 = in(1); |
| 138 | #ifdef ASSERT1 |
| 139 | // Check for dead loop |
| 140 | int op1 = mul1->Opcode(); |
| 141 | if ((mul1 == this) || (in(2) == this) || |
| 142 | ((op1 == mul_opcode() || op1 == add_opcode()) && |
| 143 | ((mul1->in(1) == this) || (mul1->in(2) == this) || |
| 144 | (mul1->in(1) == mul1) || (mul1->in(2) == mul1)))) { |
| 145 | assert(false, "dead loop in MulNode::Ideal")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 145, "assert(" "false" ") failed", "dead loop in MulNode::Ideal" ); ::breakpoint(); } } while (0); |
| 146 | } |
| 147 | #endif |
| 148 | |
| 149 | if( mul1->Opcode() == mul_opcode() ) { // Left input is a multiply? |
| 150 | // Mul of a constant? |
| 151 | const Type *t12 = phase->type( mul1->in(2) ); |
| 152 | if( t12->singleton() && t12 != Type::TOP) { // Left input is an add of a constant? |
| 153 | // Compute new constant; check for overflow |
| 154 | const Type *tcon01 = ((MulNode*)mul1)->mul_ring(t2,t12); |
| 155 | if( tcon01->singleton() ) { |
| 156 | // The Mul of the flattened expression |
| 157 | set_req_X(1, mul1->in(1), phase); |
| 158 | set_req_X(2, phase->makecon(tcon01), phase); |
| 159 | t2 = tcon01; |
| 160 | progress = this; // Made progress |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | // If the right input is a constant, and the left input is an add of a |
| 165 | // constant, flatten the tree: (X+con1)*con0 ==> X*con0 + con1*con0 |
| 166 | const Node *add1 = in(1); |
| 167 | if( add1->Opcode() == add_opcode() ) { // Left input is an add? |
| 168 | // Add of a constant? |
| 169 | const Type *t12 = phase->type( add1->in(2) ); |
| 170 | if( t12->singleton() && t12 != Type::TOP ) { // Left input is an add of a constant? |
| 171 | assert( add1->in(1) != add1, "dead loop in MulNode::Ideal" )do { if (!(add1->in(1) != add1)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 171, "assert(" "add1->in(1) != add1" ") failed", "dead loop in MulNode::Ideal" ); ::breakpoint(); } } while (0); |
| 172 | // Compute new constant; check for overflow |
| 173 | const Type *tcon01 = mul_ring(t2,t12); |
| 174 | if( tcon01->singleton() ) { |
| 175 | |
| 176 | // Convert (X+con1)*con0 into X*con0 |
| 177 | Node *mul = clone(); // mul = ()*con0 |
| 178 | mul->set_req(1,add1->in(1)); // mul = X*con0 |
| 179 | mul = phase->transform(mul); |
| 180 | |
| 181 | Node *add2 = add1->clone(); |
| 182 | add2->set_req(1, mul); // X*con0 + con0*con1 |
| 183 | add2->set_req(2, phase->makecon(tcon01) ); |
| 184 | progress = add2; |
| 185 | } |
| 186 | } |
| 187 | } // End of is left input an add |
| 188 | } // End of is right input a Mul |
| 189 | |
| 190 | return progress; |
| 191 | } |
| 192 | |
| 193 | //------------------------------Value----------------------------------------- |
| 194 | const Type* MulNode::Value(PhaseGVN* phase) const { |
| 195 | const Type *t1 = phase->type( in(1) ); |
| 196 | const Type *t2 = phase->type( in(2) ); |
| 197 | // Either input is TOP ==> the result is TOP |
| 198 | if( t1 == Type::TOP ) return Type::TOP; |
| 199 | if( t2 == Type::TOP ) return Type::TOP; |
| 200 | |
| 201 | // Either input is ZERO ==> the result is ZERO. |
| 202 | // Not valid for floats or doubles since +0.0 * -0.0 --> +0.0 |
| 203 | int op = Opcode(); |
| 204 | if( op == Op_MulI || op == Op_AndI || op == Op_MulL || op == Op_AndL ) { |
| 205 | const Type *zero = add_id(); // The multiplicative zero |
| 206 | if( t1->higher_equal( zero ) ) return zero; |
| 207 | if( t2->higher_equal( zero ) ) return zero; |
| 208 | } |
| 209 | |
| 210 | // Either input is BOTTOM ==> the result is the local BOTTOM |
| 211 | if( t1 == Type::BOTTOM || t2 == Type::BOTTOM ) |
| 212 | return bottom_type(); |
| 213 | |
| 214 | #if defined(IA32) |
| 215 | // Can't trust native compilers to properly fold strict double |
| 216 | // multiplication with round-to-zero on this platform. |
| 217 | if (op == Op_MulD) { |
| 218 | return TypeD::DOUBLE; |
| 219 | } |
| 220 | #endif |
| 221 | |
| 222 | return mul_ring(t1,t2); // Local flavor of type multiplication |
| 223 | } |
| 224 | |
| 225 | MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) { |
| 226 | switch (bt) { |
| 227 | case T_INT: |
| 228 | return new MulINode(in1, in2); |
| 229 | case T_LONG: |
| 230 | return new MulLNode(in1, in2); |
| 231 | default: |
| 232 | fatal("Not implemented for %s", type2name(bt))do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 232, "Not implemented for %s", type2name(bt)); ::breakpoint (); } while (0); |
| 233 | } |
| 234 | return NULL__null; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | //============================================================================= |
| 239 | //------------------------------Ideal------------------------------------------ |
| 240 | // Check for power-of-2 multiply, then try the regular MulNode::Ideal |
| 241 | Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 242 | // Swap constant to right |
| 243 | jint con; |
| 244 | if ((con = in(1)->find_int_con(0)) != 0) { |
| 245 | swap_edges(1, 2); |
| 246 | // Finish rest of method to use info in 'con' |
| 247 | } else if ((con = in(2)->find_int_con(0)) == 0) { |
| 248 | return MulNode::Ideal(phase, can_reshape); |
| 249 | } |
| 250 | |
| 251 | // Now we have a constant Node on the right and the constant in con |
| 252 | if (con == 0) return NULL__null; // By zero is handled by Value call |
| 253 | if (con == 1) return NULL__null; // By one is handled by Identity call |
| 254 | |
| 255 | // Check for negative constant; if so negate the final result |
| 256 | bool sign_flip = false; |
| 257 | |
| 258 | unsigned int abs_con = uabs(con); |
| 259 | if (abs_con != (unsigned int)con) { |
| 260 | sign_flip = true; |
| 261 | } |
| 262 | |
| 263 | // Get low bit; check for being the only bit |
| 264 | Node *res = NULL__null; |
| 265 | unsigned int bit1 = abs_con & (0-abs_con); // Extract low bit |
| 266 | if (bit1 == abs_con) { // Found a power of 2? |
| 267 | res = new LShiftINode(in(1), phase->intcon(log2i_exact(bit1))); |
| 268 | } else { |
| 269 | // Check for constant with 2 bits set |
| 270 | unsigned int bit2 = abs_con - bit1; |
| 271 | bit2 = bit2 & (0 - bit2); // Extract 2nd bit |
| 272 | if (bit2 + bit1 == abs_con) { // Found all bits in con? |
| 273 | Node *n1 = phase->transform(new LShiftINode(in(1), phase->intcon(log2i_exact(bit1)))); |
| 274 | Node *n2 = phase->transform(new LShiftINode(in(1), phase->intcon(log2i_exact(bit2)))); |
| 275 | res = new AddINode(n2, n1); |
| 276 | } else if (is_power_of_2(abs_con + 1)) { |
| 277 | // Sleezy: power-of-2 - 1. Next time be generic. |
| 278 | unsigned int temp = abs_con + 1; |
| 279 | Node *n1 = phase->transform(new LShiftINode(in(1), phase->intcon(log2i_exact(temp)))); |
| 280 | res = new SubINode(n1, in(1)); |
| 281 | } else { |
| 282 | return MulNode::Ideal(phase, can_reshape); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (sign_flip) { // Need to negate result? |
| 287 | res = phase->transform(res);// Transform, before making the zero con |
| 288 | res = new SubINode(phase->intcon(0),res); |
| 289 | } |
| 290 | |
| 291 | return res; // Return final result |
| 292 | } |
| 293 | |
| 294 | //------------------------------mul_ring--------------------------------------- |
| 295 | // Compute the product type of two integer ranges into this node. |
| 296 | const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const { |
| 297 | const TypeInt *r0 = t0->is_int(); // Handy access |
| 298 | const TypeInt *r1 = t1->is_int(); |
| 299 | |
| 300 | // Fetch endpoints of all ranges |
| 301 | jint lo0 = r0->_lo; |
| 302 | double a = (double)lo0; |
| 303 | jint hi0 = r0->_hi; |
| 304 | double b = (double)hi0; |
| 305 | jint lo1 = r1->_lo; |
| 306 | double c = (double)lo1; |
| 307 | jint hi1 = r1->_hi; |
| 308 | double d = (double)hi1; |
| 309 | |
| 310 | // Compute all endpoints & check for overflow |
| 311 | int32_t A = java_multiply(lo0, lo1); |
| 312 | if( (double)A != a*c ) return TypeInt::INT; // Overflow? |
| 313 | int32_t B = java_multiply(lo0, hi1); |
| 314 | if( (double)B != a*d ) return TypeInt::INT; // Overflow? |
| 315 | int32_t C = java_multiply(hi0, lo1); |
| 316 | if( (double)C != b*c ) return TypeInt::INT; // Overflow? |
| 317 | int32_t D = java_multiply(hi0, hi1); |
| 318 | if( (double)D != b*d ) return TypeInt::INT; // Overflow? |
| 319 | |
| 320 | if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints |
| 321 | else { lo0 = B; hi0 = A; } |
| 322 | if( C < D ) { |
| 323 | if( C < lo0 ) lo0 = C; |
| 324 | if( D > hi0 ) hi0 = D; |
| 325 | } else { |
| 326 | if( D < lo0 ) lo0 = D; |
| 327 | if( C > hi0 ) hi0 = C; |
| 328 | } |
| 329 | return TypeInt::make(lo0, hi0, MAX2(r0->_widen,r1->_widen)); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | //============================================================================= |
| 334 | //------------------------------Ideal------------------------------------------ |
| 335 | // Check for power-of-2 multiply, then try the regular MulNode::Ideal |
| 336 | Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 337 | // Swap constant to right |
| 338 | jlong con; |
| 339 | if ((con = in(1)->find_long_con(0)) != 0) { |
| 340 | swap_edges(1, 2); |
| 341 | // Finish rest of method to use info in 'con' |
| 342 | } else if ((con = in(2)->find_long_con(0)) == 0) { |
| 343 | return MulNode::Ideal(phase, can_reshape); |
| 344 | } |
| 345 | |
| 346 | // Now we have a constant Node on the right and the constant in con |
| 347 | if (con == CONST64(0)(0LL)) return NULL__null; // By zero is handled by Value call |
| 348 | if (con == CONST64(1)(1LL)) return NULL__null; // By one is handled by Identity call |
| 349 | |
| 350 | // Check for negative constant; if so negate the final result |
| 351 | bool sign_flip = false; |
| 352 | julong abs_con = uabs(con); |
| 353 | if (abs_con != (julong)con) { |
| 354 | sign_flip = true; |
| 355 | } |
| 356 | |
| 357 | // Get low bit; check for being the only bit |
| 358 | Node *res = NULL__null; |
| 359 | julong bit1 = abs_con & (0-abs_con); // Extract low bit |
| 360 | if (bit1 == abs_con) { // Found a power of 2? |
| 361 | res = new LShiftLNode(in(1), phase->intcon(log2i_exact(bit1))); |
| 362 | } else { |
| 363 | |
| 364 | // Check for constant with 2 bits set |
| 365 | julong bit2 = abs_con-bit1; |
| 366 | bit2 = bit2 & (0-bit2); // Extract 2nd bit |
| 367 | if (bit2 + bit1 == abs_con) { // Found all bits in con? |
| 368 | Node *n1 = phase->transform(new LShiftLNode(in(1), phase->intcon(log2i_exact(bit1)))); |
| 369 | Node *n2 = phase->transform(new LShiftLNode(in(1), phase->intcon(log2i_exact(bit2)))); |
| 370 | res = new AddLNode(n2, n1); |
| 371 | |
| 372 | } else if (is_power_of_2(abs_con+1)) { |
| 373 | // Sleezy: power-of-2 -1. Next time be generic. |
| 374 | julong temp = abs_con + 1; |
| 375 | Node *n1 = phase->transform( new LShiftLNode(in(1), phase->intcon(log2i_exact(temp)))); |
| 376 | res = new SubLNode(n1, in(1)); |
| 377 | } else { |
| 378 | return MulNode::Ideal(phase, can_reshape); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (sign_flip) { // Need to negate result? |
| 383 | res = phase->transform(res);// Transform, before making the zero con |
| 384 | res = new SubLNode(phase->longcon(0),res); |
| 385 | } |
| 386 | |
| 387 | return res; // Return final result |
| 388 | } |
| 389 | |
| 390 | //------------------------------mul_ring--------------------------------------- |
| 391 | // Compute the product type of two integer ranges into this node. |
| 392 | const Type *MulLNode::mul_ring(const Type *t0, const Type *t1) const { |
| 393 | const TypeLong *r0 = t0->is_long(); // Handy access |
| 394 | const TypeLong *r1 = t1->is_long(); |
| 395 | |
| 396 | // Fetch endpoints of all ranges |
| 397 | jlong lo0 = r0->_lo; |
| 398 | double a = (double)lo0; |
| 399 | jlong hi0 = r0->_hi; |
| 400 | double b = (double)hi0; |
| 401 | jlong lo1 = r1->_lo; |
| 402 | double c = (double)lo1; |
| 403 | jlong hi1 = r1->_hi; |
| 404 | double d = (double)hi1; |
| 405 | |
| 406 | // Compute all endpoints & check for overflow |
| 407 | jlong A = java_multiply(lo0, lo1); |
| 408 | if( (double)A != a*c ) return TypeLong::LONG; // Overflow? |
| 409 | jlong B = java_multiply(lo0, hi1); |
| 410 | if( (double)B != a*d ) return TypeLong::LONG; // Overflow? |
| 411 | jlong C = java_multiply(hi0, lo1); |
| 412 | if( (double)C != b*c ) return TypeLong::LONG; // Overflow? |
| 413 | jlong D = java_multiply(hi0, hi1); |
| 414 | if( (double)D != b*d ) return TypeLong::LONG; // Overflow? |
| 415 | |
| 416 | if( A < B ) { lo0 = A; hi0 = B; } // Sort range endpoints |
| 417 | else { lo0 = B; hi0 = A; } |
| 418 | if( C < D ) { |
| 419 | if( C < lo0 ) lo0 = C; |
| 420 | if( D > hi0 ) hi0 = D; |
| 421 | } else { |
| 422 | if( D < lo0 ) lo0 = D; |
| 423 | if( C > hi0 ) hi0 = C; |
| 424 | } |
| 425 | return TypeLong::make(lo0, hi0, MAX2(r0->_widen,r1->_widen)); |
| 426 | } |
| 427 | |
| 428 | //============================================================================= |
| 429 | //------------------------------mul_ring--------------------------------------- |
| 430 | // Compute the product type of two double ranges into this node. |
| 431 | const Type *MulFNode::mul_ring(const Type *t0, const Type *t1) const { |
| 432 | if( t0 == Type::FLOAT || t1 == Type::FLOAT ) return Type::FLOAT; |
| 433 | return TypeF::make( t0->getf() * t1->getf() ); |
| 434 | } |
| 435 | |
| 436 | //============================================================================= |
| 437 | //------------------------------mul_ring--------------------------------------- |
| 438 | // Compute the product type of two double ranges into this node. |
| 439 | const Type *MulDNode::mul_ring(const Type *t0, const Type *t1) const { |
| 440 | if( t0 == Type::DOUBLE || t1 == Type::DOUBLE ) return Type::DOUBLE; |
| 441 | // We must be multiplying 2 double constants. |
| 442 | return TypeD::make( t0->getd() * t1->getd() ); |
| 443 | } |
| 444 | |
| 445 | //============================================================================= |
| 446 | //------------------------------Value------------------------------------------ |
| 447 | const Type* MulHiLNode::Value(PhaseGVN* phase) const { |
| 448 | const Type *t1 = phase->type( in(1) ); |
| 449 | const Type *t2 = phase->type( in(2) ); |
| 450 | const Type *bot = bottom_type(); |
| 451 | return MulHiValue(t1, t2, bot); |
| 452 | } |
| 453 | |
| 454 | const Type* UMulHiLNode::Value(PhaseGVN* phase) const { |
| 455 | const Type *t1 = phase->type( in(1) ); |
| 456 | const Type *t2 = phase->type( in(2) ); |
| 457 | const Type *bot = bottom_type(); |
| 458 | return MulHiValue(t1, t2, bot); |
| 459 | } |
| 460 | |
| 461 | // A common routine used by UMulHiLNode and MulHiLNode |
| 462 | const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot) { |
| 463 | // Either input is TOP ==> the result is TOP |
| 464 | if( t1 == Type::TOP ) return Type::TOP; |
| 465 | if( t2 == Type::TOP ) return Type::TOP; |
| 466 | |
| 467 | // Either input is BOTTOM ==> the result is the local BOTTOM |
| 468 | if( (t1 == bot) || (t2 == bot) || |
| 469 | (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
| 470 | return bot; |
| 471 | |
| 472 | // It is not worth trying to constant fold this stuff! |
| 473 | return TypeLong::LONG; |
| 474 | } |
| 475 | |
| 476 | //============================================================================= |
| 477 | //------------------------------mul_ring--------------------------------------- |
| 478 | // Supplied function returns the product of the inputs IN THE CURRENT RING. |
| 479 | // For the logical operations the ring's MUL is really a logical AND function. |
| 480 | // This also type-checks the inputs for sanity. Guaranteed never to |
| 481 | // be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
| 482 | const Type *AndINode::mul_ring( const Type *t0, const Type *t1 ) const { |
| 483 | const TypeInt *r0 = t0->is_int(); // Handy access |
| 484 | const TypeInt *r1 = t1->is_int(); |
| 485 | int widen = MAX2(r0->_widen,r1->_widen); |
| 486 | |
| 487 | // If either input is a constant, might be able to trim cases |
| 488 | if( !r0->is_con() && !r1->is_con() ) |
| 489 | return TypeInt::INT; // No constants to be had |
| 490 | |
| 491 | // Both constants? Return bits |
| 492 | if( r0->is_con() && r1->is_con() ) |
| 493 | return TypeInt::make( r0->get_con() & r1->get_con() ); |
| 494 | |
| 495 | if( r0->is_con() && r0->get_con() > 0 ) |
| 496 | return TypeInt::make(0, r0->get_con(), widen); |
| 497 | |
| 498 | if( r1->is_con() && r1->get_con() > 0 ) |
| 499 | return TypeInt::make(0, r1->get_con(), widen); |
| 500 | |
| 501 | if( r0 == TypeInt::BOOL || r1 == TypeInt::BOOL ) { |
| 502 | return TypeInt::BOOL; |
| 503 | } |
| 504 | |
| 505 | return TypeInt::INT; // No constants to be had |
| 506 | } |
| 507 | |
| 508 | const Type* AndINode::Value(PhaseGVN* phase) const { |
| 509 | // patterns similar to (v << 2) & 3 |
| 510 | if (AndIL_shift_and_mask(phase, in(2), in(1), T_INT)) { |
| 511 | return TypeInt::ZERO; |
| 512 | } |
| 513 | |
| 514 | return MulNode::Value(phase); |
| 515 | } |
| 516 | |
| 517 | //------------------------------Identity--------------------------------------- |
| 518 | // Masking off the high bits of an unsigned load is not required |
| 519 | Node* AndINode::Identity(PhaseGVN* phase) { |
| 520 | |
| 521 | // x & x => x |
| 522 | if (in(1) == in(2)) { |
| 523 | return in(1); |
| 524 | } |
| 525 | |
| 526 | Node* in1 = in(1); |
| 527 | uint op = in1->Opcode(); |
| 528 | const TypeInt* t2 = phase->type(in(2))->isa_int(); |
| 529 | if (t2 && t2->is_con()) { |
| 530 | int con = t2->get_con(); |
| 531 | // Masking off high bits which are always zero is useless. |
| 532 | const TypeInt* t1 = phase->type(in(1))->isa_int(); |
| 533 | if (t1 != NULL__null && t1->_lo >= 0) { |
| 534 | jint t1_support = right_n_bits(1 + log2i_graceful(t1->_hi))((((1 + log2i_graceful(t1->_hi)) >= BitsPerWord) ? 0 : ( OneBit << (1 + log2i_graceful(t1->_hi)))) - 1); |
| 535 | if ((t1_support & con) == t1_support) |
| 536 | return in1; |
| 537 | } |
| 538 | // Masking off the high bits of a unsigned-shift-right is not |
| 539 | // needed either. |
| 540 | if (op == Op_URShiftI) { |
| 541 | const TypeInt* t12 = phase->type(in1->in(2))->isa_int(); |
| 542 | if (t12 && t12->is_con()) { // Shift is by a constant |
| 543 | int shift = t12->get_con(); |
| 544 | shift &= BitsPerJavaInteger - 1; // semantics of Java shifts |
| 545 | int mask = max_juint >> shift; |
| 546 | if ((mask & con) == mask) // If AND is useless, skip it |
| 547 | return in1; |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | return MulNode::Identity(phase); |
| 552 | } |
| 553 | |
| 554 | //------------------------------Ideal------------------------------------------ |
| 555 | Node *AndINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 556 | // Special case constant AND mask |
| 557 | const TypeInt *t2 = phase->type( in(2) )->isa_int(); |
| 558 | if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape); |
| 559 | const int mask = t2->get_con(); |
| 560 | Node *load = in(1); |
| 561 | uint lop = load->Opcode(); |
| 562 | |
| 563 | // Masking bits off of a Character? Hi bits are already zero. |
| 564 | if( lop == Op_LoadUS && |
| 565 | (mask & 0xFFFF0000) ) // Can we make a smaller mask? |
| 566 | return new AndINode(load,phase->intcon(mask&0xFFFF)); |
| 567 | |
| 568 | // Masking bits off of a Short? Loading a Character does some masking |
| 569 | if (can_reshape && |
| 570 | load->outcnt() == 1 && load->unique_out() == this) { |
| 571 | if (lop == Op_LoadS && (mask & 0xFFFF0000) == 0 ) { |
| 572 | Node* ldus = load->as_Load()->convert_to_unsigned_load(*phase); |
| 573 | ldus = phase->transform(ldus); |
| 574 | return new AndINode(ldus, phase->intcon(mask & 0xFFFF)); |
| 575 | } |
| 576 | |
| 577 | // Masking sign bits off of a Byte? Do an unsigned byte load plus |
| 578 | // an and. |
| 579 | if (lop == Op_LoadB && (mask & 0xFFFFFF00) == 0) { |
| 580 | Node* ldub = load->as_Load()->convert_to_unsigned_load(*phase); |
| 581 | ldub = phase->transform(ldub); |
| 582 | return new AndINode(ldub, phase->intcon(mask)); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | // Masking off sign bits? Dont make them! |
| 587 | if( lop == Op_RShiftI ) { |
| 588 | const TypeInt *t12 = phase->type(load->in(2))->isa_int(); |
| 589 | if( t12 && t12->is_con() ) { // Shift is by a constant |
| 590 | int shift = t12->get_con(); |
| 591 | shift &= BitsPerJavaInteger-1; // semantics of Java shifts |
| 592 | const int sign_bits_mask = ~right_n_bits(BitsPerJavaInteger - shift)((((BitsPerJavaInteger - shift) >= BitsPerWord) ? 0 : (OneBit << (BitsPerJavaInteger - shift))) - 1); |
| 593 | // If the AND'ing of the 2 masks has no bits, then only original shifted |
| 594 | // bits survive. NO sign-extension bits survive the maskings. |
| 595 | if( (sign_bits_mask & mask) == 0 ) { |
| 596 | // Use zero-fill shift instead |
| 597 | Node *zshift = phase->transform(new URShiftINode(load->in(1),load->in(2))); |
| 598 | return new AndINode( zshift, in(2) ); |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | // Check for 'negate/and-1', a pattern emitted when someone asks for |
| 604 | // 'mod 2'. Negate leaves the low order bit unchanged (think: complement |
| 605 | // plus 1) and the mask is of the low order bit. Skip the negate. |
| 606 | if( lop == Op_SubI && mask == 1 && load->in(1) && |
| 607 | phase->type(load->in(1)) == TypeInt::ZERO ) |
| 608 | return new AndINode( load->in(2), in(2) ); |
| 609 | |
| 610 | // pattern similar to (v1 + (v2 << 2)) & 3 transformed to v1 & 3 |
| 611 | Node* progress = AndIL_add_shift_and_mask(phase, T_INT); |
| 612 | if (progress != NULL__null) { |
| 613 | return progress; |
| 614 | } |
| 615 | |
| 616 | return MulNode::Ideal(phase, can_reshape); |
| 617 | } |
| 618 | |
| 619 | //============================================================================= |
| 620 | //------------------------------mul_ring--------------------------------------- |
| 621 | // Supplied function returns the product of the inputs IN THE CURRENT RING. |
| 622 | // For the logical operations the ring's MUL is really a logical AND function. |
| 623 | // This also type-checks the inputs for sanity. Guaranteed never to |
| 624 | // be passed a TOP or BOTTOM type, these are filtered out by pre-check. |
| 625 | const Type *AndLNode::mul_ring( const Type *t0, const Type *t1 ) const { |
| 626 | const TypeLong *r0 = t0->is_long(); // Handy access |
| 627 | const TypeLong *r1 = t1->is_long(); |
| 628 | int widen = MAX2(r0->_widen,r1->_widen); |
| 629 | |
| 630 | // If either input is a constant, might be able to trim cases |
| 631 | if( !r0->is_con() && !r1->is_con() ) |
| 632 | return TypeLong::LONG; // No constants to be had |
| 633 | |
| 634 | // Both constants? Return bits |
| 635 | if( r0->is_con() && r1->is_con() ) |
| 636 | return TypeLong::make( r0->get_con() & r1->get_con() ); |
| 637 | |
| 638 | if( r0->is_con() && r0->get_con() > 0 ) |
| 639 | return TypeLong::make(CONST64(0)(0LL), r0->get_con(), widen); |
| 640 | |
| 641 | if( r1->is_con() && r1->get_con() > 0 ) |
| 642 | return TypeLong::make(CONST64(0)(0LL), r1->get_con(), widen); |
| 643 | |
| 644 | return TypeLong::LONG; // No constants to be had |
| 645 | } |
| 646 | |
| 647 | const Type* AndLNode::Value(PhaseGVN* phase) const { |
| 648 | // patterns similar to (v << 2) & 3 |
| 649 | if (AndIL_shift_and_mask(phase, in(2), in(1), T_LONG)) { |
| 650 | return TypeLong::ZERO; |
| 651 | } |
| 652 | |
| 653 | return MulNode::Value(phase); |
| 654 | } |
| 655 | |
| 656 | //------------------------------Identity--------------------------------------- |
| 657 | // Masking off the high bits of an unsigned load is not required |
| 658 | Node* AndLNode::Identity(PhaseGVN* phase) { |
| 659 | |
| 660 | // x & x => x |
| 661 | if (in(1) == in(2)) { |
| 662 | return in(1); |
| 663 | } |
| 664 | |
| 665 | Node *usr = in(1); |
| 666 | const TypeLong *t2 = phase->type( in(2) )->isa_long(); |
| 667 | if( t2 && t2->is_con() ) { |
| 668 | jlong con = t2->get_con(); |
| 669 | // Masking off high bits which are always zero is useless. |
| 670 | const TypeLong* t1 = phase->type( in(1) )->isa_long(); |
| 671 | if (t1 != NULL__null && t1->_lo >= 0) { |
| 672 | int bit_count = log2i_graceful(t1->_hi) + 1; |
| 673 | jlong t1_support = jlong(max_julong >> (BitsPerJavaLong - bit_count)); |
| 674 | if ((t1_support & con) == t1_support) |
| 675 | return usr; |
| 676 | } |
| 677 | uint lop = usr->Opcode(); |
| 678 | // Masking off the high bits of a unsigned-shift-right is not |
| 679 | // needed either. |
| 680 | if( lop == Op_URShiftL ) { |
| 681 | const TypeInt *t12 = phase->type( usr->in(2) )->isa_int(); |
| 682 | if( t12 && t12->is_con() ) { // Shift is by a constant |
| 683 | int shift = t12->get_con(); |
| 684 | shift &= BitsPerJavaLong - 1; // semantics of Java shifts |
| 685 | jlong mask = max_julong >> shift; |
| 686 | if( (mask&con) == mask ) // If AND is useless, skip it |
| 687 | return usr; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | return MulNode::Identity(phase); |
| 692 | } |
| 693 | |
| 694 | //------------------------------Ideal------------------------------------------ |
| 695 | Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 696 | // Special case constant AND mask |
| 697 | const TypeLong *t2 = phase->type( in(2) )->isa_long(); |
| 698 | if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape); |
| 699 | const jlong mask = t2->get_con(); |
| 700 | |
| 701 | Node* in1 = in(1); |
| 702 | int op = in1->Opcode(); |
| 703 | |
| 704 | // Are we masking a long that was converted from an int with a mask |
| 705 | // that fits in 32-bits? Commute them and use an AndINode. Don't |
| 706 | // convert masks which would cause a sign extension of the integer |
| 707 | // value. This check includes UI2L masks (0x00000000FFFFFFFF) which |
| 708 | // would be optimized away later in Identity. |
| 709 | if (op == Op_ConvI2L && (mask & UCONST64(0xFFFFFFFF80000000)(0xFFFFFFFF80000000ULL)) == 0) { |
| 710 | Node* andi = new AndINode(in1->in(1), phase->intcon(mask)); |
| 711 | andi = phase->transform(andi); |
| 712 | return new ConvI2LNode(andi); |
| 713 | } |
| 714 | |
| 715 | // Masking off sign bits? Dont make them! |
| 716 | if (op == Op_RShiftL) { |
| 717 | const TypeInt* t12 = phase->type(in1->in(2))->isa_int(); |
| 718 | if( t12 && t12->is_con() ) { // Shift is by a constant |
| 719 | int shift = t12->get_con(); |
| 720 | shift &= BitsPerJavaLong - 1; // semantics of Java shifts |
| 721 | const jlong sign_bits_mask = ~(((jlong)CONST64(1)(1LL) << (jlong)(BitsPerJavaLong - shift)) -1); |
| 722 | // If the AND'ing of the 2 masks has no bits, then only original shifted |
| 723 | // bits survive. NO sign-extension bits survive the maskings. |
| 724 | if( (sign_bits_mask & mask) == 0 ) { |
| 725 | // Use zero-fill shift instead |
| 726 | Node *zshift = phase->transform(new URShiftLNode(in1->in(1), in1->in(2))); |
| 727 | return new AndLNode(zshift, in(2)); |
| 728 | } |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | // pattern similar to (v1 + (v2 << 2)) & 3 transformed to v1 & 3 |
| 733 | Node* progress = AndIL_add_shift_and_mask(phase, T_LONG); |
| 734 | if (progress != NULL__null) { |
| 735 | return progress; |
| 736 | } |
| 737 | |
| 738 | return MulNode::Ideal(phase, can_reshape); |
| 739 | } |
| 740 | |
| 741 | //============================================================================= |
| 742 | |
| 743 | static bool const_shift_count(PhaseGVN* phase, Node* shiftNode, int* count) { |
| 744 | const TypeInt* tcount = phase->type(shiftNode->in(2))->isa_int(); |
| 745 | if (tcount != NULL__null && tcount->is_con()) { |
| 746 | *count = tcount->get_con(); |
| 747 | return true; |
| 748 | } |
| 749 | return false; |
| 750 | } |
| 751 | |
| 752 | static int maskShiftAmount(PhaseGVN* phase, Node* shiftNode, int nBits) { |
| 753 | int count = 0; |
| 754 | if (const_shift_count(phase, shiftNode, &count)) { |
| 755 | int maskedShift = count & (nBits - 1); |
| 756 | if (maskedShift == 0) { |
| 757 | // Let Identity() handle 0 shift count. |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | if (count != maskedShift) { |
| 762 | shiftNode->set_req(2, phase->intcon(maskedShift)); // Replace shift count with masked value. |
| 763 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
| 764 | if (igvn) { |
| 765 | igvn->rehash_node_delayed(shiftNode); |
| 766 | } |
| 767 | } |
| 768 | return maskedShift; |
| 769 | } |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | //------------------------------Identity--------------------------------------- |
| 774 | Node* LShiftINode::Identity(PhaseGVN* phase) { |
| 775 | int count = 0; |
| 776 | if (const_shift_count(phase, this, &count) && (count & (BitsPerJavaInteger - 1)) == 0) { |
| 777 | // Shift by a multiple of 32 does nothing |
| 778 | return in(1); |
| 779 | } |
| 780 | return this; |
| 781 | } |
| 782 | |
| 783 | //------------------------------Ideal------------------------------------------ |
| 784 | // If the right input is a constant, and the left input is an add of a |
| 785 | // constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0 |
| 786 | Node *LShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 787 | int con = maskShiftAmount(phase, this, BitsPerJavaInteger); |
| 788 | if (con == 0) { |
| 789 | return NULL__null; |
| 790 | } |
| 791 | |
| 792 | // Left input is an add of a constant? |
| 793 | Node *add1 = in(1); |
| 794 | int add1_op = add1->Opcode(); |
| 795 | if( add1_op == Op_AddI ) { // Left input is an add? |
| 796 | assert( add1 != add1->in(1), "dead loop in LShiftINode::Ideal" )do { if (!(add1 != add1->in(1))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 796, "assert(" "add1 != add1->in(1)" ") failed", "dead loop in LShiftINode::Ideal" ); ::breakpoint(); } } while (0); |
| 797 | const TypeInt *t12 = phase->type(add1->in(2))->isa_int(); |
| 798 | if( t12 && t12->is_con() ){ // Left input is an add of a con? |
| 799 | // Transform is legal, but check for profit. Avoid breaking 'i2s' |
| 800 | // and 'i2b' patterns which typically fold into 'StoreC/StoreB'. |
| 801 | if( con < 16 ) { |
| 802 | // Compute X << con0 |
| 803 | Node *lsh = phase->transform( new LShiftINode( add1->in(1), in(2) ) ); |
| 804 | // Compute X<<con0 + (con1<<con0) |
| 805 | return new AddINode( lsh, phase->intcon(t12->get_con() << con)); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | // Check for "(x>>c0)<<c0" which just masks off low bits |
| 811 | if( (add1_op == Op_RShiftI || add1_op == Op_URShiftI ) && |
| 812 | add1->in(2) == in(2) ) |
| 813 | // Convert to "(x & -(1<<c0))" |
| 814 | return new AndINode(add1->in(1),phase->intcon( -(1<<con))); |
| 815 | |
| 816 | // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits |
| 817 | if( add1_op == Op_AndI ) { |
| 818 | Node *add2 = add1->in(1); |
| 819 | int add2_op = add2->Opcode(); |
| 820 | if( (add2_op == Op_RShiftI || add2_op == Op_URShiftI ) && |
| 821 | add2->in(2) == in(2) ) { |
| 822 | // Convert to "(x & (Y<<c0))" |
| 823 | Node *y_sh = phase->transform( new LShiftINode( add1->in(2), in(2) ) ); |
| 824 | return new AndINode( add2->in(1), y_sh ); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | // Check for ((x & ((1<<(32-c0))-1)) << c0) which ANDs off high bits |
| 829 | // before shifting them away. |
| 830 | const jint bits_mask = right_n_bits(BitsPerJavaInteger-con)((((BitsPerJavaInteger-con) >= BitsPerWord) ? 0 : (OneBit << (BitsPerJavaInteger-con))) - 1); |
| 831 | if( add1_op == Op_AndI && |
| 832 | phase->type(add1->in(2)) == TypeInt::make( bits_mask ) ) |
| 833 | return new LShiftINode( add1->in(1), in(2) ); |
| 834 | |
| 835 | return NULL__null; |
| 836 | } |
| 837 | |
| 838 | //------------------------------Value------------------------------------------ |
| 839 | // A LShiftINode shifts its input2 left by input1 amount. |
| 840 | const Type* LShiftINode::Value(PhaseGVN* phase) const { |
| 841 | const Type *t1 = phase->type( in(1) ); |
| 842 | const Type *t2 = phase->type( in(2) ); |
| 843 | // Either input is TOP ==> the result is TOP |
| 844 | if( t1 == Type::TOP ) return Type::TOP; |
| 845 | if( t2 == Type::TOP ) return Type::TOP; |
| 846 | |
| 847 | // Left input is ZERO ==> the result is ZERO. |
| 848 | if( t1 == TypeInt::ZERO ) return TypeInt::ZERO; |
| 849 | // Shift by zero does nothing |
| 850 | if( t2 == TypeInt::ZERO ) return t1; |
| 851 | |
| 852 | // Either input is BOTTOM ==> the result is BOTTOM |
| 853 | if( (t1 == TypeInt::INT) || (t2 == TypeInt::INT) || |
| 854 | (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
| 855 | return TypeInt::INT; |
| 856 | |
| 857 | const TypeInt *r1 = t1->is_int(); // Handy access |
| 858 | const TypeInt *r2 = t2->is_int(); // Handy access |
| 859 | |
| 860 | if (!r2->is_con()) |
| 861 | return TypeInt::INT; |
| 862 | |
| 863 | uint shift = r2->get_con(); |
| 864 | shift &= BitsPerJavaInteger-1; // semantics of Java shifts |
| 865 | // Shift by a multiple of 32 does nothing: |
| 866 | if (shift == 0) return t1; |
| 867 | |
| 868 | // If the shift is a constant, shift the bounds of the type, |
| 869 | // unless this could lead to an overflow. |
| 870 | if (!r1->is_con()) { |
| 871 | jint lo = r1->_lo, hi = r1->_hi; |
| 872 | if (((lo << shift) >> shift) == lo && |
| 873 | ((hi << shift) >> shift) == hi) { |
| 874 | // No overflow. The range shifts up cleanly. |
| 875 | return TypeInt::make((jint)lo << (jint)shift, |
| 876 | (jint)hi << (jint)shift, |
| 877 | MAX2(r1->_widen,r2->_widen)); |
| 878 | } |
| 879 | return TypeInt::INT; |
| 880 | } |
| 881 | |
| 882 | return TypeInt::make( (jint)r1->get_con() << (jint)shift ); |
| 883 | } |
| 884 | |
| 885 | //============================================================================= |
| 886 | //------------------------------Identity--------------------------------------- |
| 887 | Node* LShiftLNode::Identity(PhaseGVN* phase) { |
| 888 | int count = 0; |
| 889 | if (const_shift_count(phase, this, &count) && (count & (BitsPerJavaLong - 1)) == 0) { |
| 890 | // Shift by a multiple of 64 does nothing |
| 891 | return in(1); |
| 892 | } |
| 893 | return this; |
| 894 | } |
| 895 | |
| 896 | //------------------------------Ideal------------------------------------------ |
| 897 | // If the right input is a constant, and the left input is an add of a |
| 898 | // constant, flatten the tree: (X+con1)<<con0 ==> X<<con0 + con1<<con0 |
| 899 | Node *LShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 900 | int con = maskShiftAmount(phase, this, BitsPerJavaLong); |
| 901 | if (con == 0) { |
| 902 | return NULL__null; |
| 903 | } |
| 904 | |
| 905 | // Left input is an add of a constant? |
| 906 | Node *add1 = in(1); |
| 907 | int add1_op = add1->Opcode(); |
| 908 | if( add1_op == Op_AddL ) { // Left input is an add? |
| 909 | // Avoid dead data cycles from dead loops |
| 910 | assert( add1 != add1->in(1), "dead loop in LShiftLNode::Ideal" )do { if (!(add1 != add1->in(1))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 910, "assert(" "add1 != add1->in(1)" ") failed", "dead loop in LShiftLNode::Ideal" ); ::breakpoint(); } } while (0); |
| 911 | const TypeLong *t12 = phase->type(add1->in(2))->isa_long(); |
| 912 | if( t12 && t12->is_con() ){ // Left input is an add of a con? |
| 913 | // Compute X << con0 |
| 914 | Node *lsh = phase->transform( new LShiftLNode( add1->in(1), in(2) ) ); |
| 915 | // Compute X<<con0 + (con1<<con0) |
| 916 | return new AddLNode( lsh, phase->longcon(t12->get_con() << con)); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | // Check for "(x>>c0)<<c0" which just masks off low bits |
| 921 | if( (add1_op == Op_RShiftL || add1_op == Op_URShiftL ) && |
| 922 | add1->in(2) == in(2) ) |
| 923 | // Convert to "(x & -(1<<c0))" |
| 924 | return new AndLNode(add1->in(1),phase->longcon( -(CONST64(1)(1LL)<<con))); |
| 925 | |
| 926 | // Check for "((x>>c0) & Y)<<c0" which just masks off more low bits |
| 927 | if( add1_op == Op_AndL ) { |
| 928 | Node *add2 = add1->in(1); |
| 929 | int add2_op = add2->Opcode(); |
| 930 | if( (add2_op == Op_RShiftL || add2_op == Op_URShiftL ) && |
| 931 | add2->in(2) == in(2) ) { |
| 932 | // Convert to "(x & (Y<<c0))" |
| 933 | Node *y_sh = phase->transform( new LShiftLNode( add1->in(2), in(2) ) ); |
| 934 | return new AndLNode( add2->in(1), y_sh ); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits |
| 939 | // before shifting them away. |
| 940 | const jlong bits_mask = jlong(max_julong >> con); |
| 941 | if( add1_op == Op_AndL && |
| 942 | phase->type(add1->in(2)) == TypeLong::make( bits_mask ) ) |
| 943 | return new LShiftLNode( add1->in(1), in(2) ); |
| 944 | |
| 945 | return NULL__null; |
| 946 | } |
| 947 | |
| 948 | //------------------------------Value------------------------------------------ |
| 949 | // A LShiftLNode shifts its input2 left by input1 amount. |
| 950 | const Type* LShiftLNode::Value(PhaseGVN* phase) const { |
| 951 | const Type *t1 = phase->type( in(1) ); |
| 952 | const Type *t2 = phase->type( in(2) ); |
| 953 | // Either input is TOP ==> the result is TOP |
| 954 | if( t1 == Type::TOP ) return Type::TOP; |
| 955 | if( t2 == Type::TOP ) return Type::TOP; |
| 956 | |
| 957 | // Left input is ZERO ==> the result is ZERO. |
| 958 | if( t1 == TypeLong::ZERO ) return TypeLong::ZERO; |
| 959 | // Shift by zero does nothing |
| 960 | if( t2 == TypeInt::ZERO ) return t1; |
| 961 | |
| 962 | // Either input is BOTTOM ==> the result is BOTTOM |
| 963 | if( (t1 == TypeLong::LONG) || (t2 == TypeInt::INT) || |
| 964 | (t1 == Type::BOTTOM) || (t2 == Type::BOTTOM) ) |
| 965 | return TypeLong::LONG; |
| 966 | |
| 967 | const TypeLong *r1 = t1->is_long(); // Handy access |
| 968 | const TypeInt *r2 = t2->is_int(); // Handy access |
| 969 | |
| 970 | if (!r2->is_con()) |
| 971 | return TypeLong::LONG; |
| 972 | |
| 973 | uint shift = r2->get_con(); |
| 974 | shift &= BitsPerJavaLong - 1; // semantics of Java shifts |
| 975 | // Shift by a multiple of 64 does nothing: |
| 976 | if (shift == 0) return t1; |
| 977 | |
| 978 | // If the shift is a constant, shift the bounds of the type, |
| 979 | // unless this could lead to an overflow. |
| 980 | if (!r1->is_con()) { |
| 981 | jlong lo = r1->_lo, hi = r1->_hi; |
| 982 | if (((lo << shift) >> shift) == lo && |
| 983 | ((hi << shift) >> shift) == hi) { |
| 984 | // No overflow. The range shifts up cleanly. |
| 985 | return TypeLong::make((jlong)lo << (jint)shift, |
| 986 | (jlong)hi << (jint)shift, |
| 987 | MAX2(r1->_widen,r2->_widen)); |
| 988 | } |
| 989 | return TypeLong::LONG; |
| 990 | } |
| 991 | |
| 992 | return TypeLong::make( (jlong)r1->get_con() << (jint)shift ); |
| 993 | } |
| 994 | |
| 995 | //============================================================================= |
| 996 | //------------------------------Identity--------------------------------------- |
| 997 | Node* RShiftINode::Identity(PhaseGVN* phase) { |
| 998 | int count = 0; |
| 999 | if (const_shift_count(phase, this, &count)) { |
| 1000 | if ((count & (BitsPerJavaInteger - 1)) == 0) { |
| 1001 | // Shift by a multiple of 32 does nothing |
| 1002 | return in(1); |
| 1003 | } |
| 1004 | // Check for useless sign-masking |
| 1005 | if (in(1)->Opcode() == Op_LShiftI && |
| 1006 | in(1)->req() == 3 && |
| 1007 | in(1)->in(2) == in(2)) { |
| 1008 | count &= BitsPerJavaInteger-1; // semantics of Java shifts |
| 1009 | // Compute masks for which this shifting doesn't change |
| 1010 | int lo = (-1 << (BitsPerJavaInteger - ((uint)count)-1)); // FFFF8000 |
| 1011 | int hi = ~lo; // 00007FFF |
| 1012 | const TypeInt* t11 = phase->type(in(1)->in(1))->isa_int(); |
| 1013 | if (t11 == NULL__null) { |
| 1014 | return this; |
| 1015 | } |
| 1016 | // Does actual value fit inside of mask? |
| 1017 | if (lo <= t11->_lo && t11->_hi <= hi) { |
| 1018 | return in(1)->in(1); // Then shifting is a nop |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | return this; |
| 1023 | } |
| 1024 | |
| 1025 | //------------------------------Ideal------------------------------------------ |
| 1026 | Node *RShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 1027 | // Inputs may be TOP if they are dead. |
| 1028 | const TypeInt *t1 = phase->type(in(1))->isa_int(); |
| 1029 | if (!t1) return NULL__null; // Left input is an integer |
| 1030 | const TypeInt *t3; // type of in(1).in(2) |
| 1031 | int shift = maskShiftAmount(phase, this, BitsPerJavaInteger); |
| 1032 | if (shift == 0) { |
| 1033 | return NULL__null; |
| 1034 | } |
| 1035 | |
| 1036 | // Check for (x & 0xFF000000) >> 24, whose mask can be made smaller. |
| 1037 | // Such expressions arise normally from shift chains like (byte)(x >> 24). |
| 1038 | const Node *mask = in(1); |
| 1039 | if( mask->Opcode() == Op_AndI && |
| 1040 | (t3 = phase->type(mask->in(2))->isa_int()) && |
| 1041 | t3->is_con() ) { |
| 1042 | Node *x = mask->in(1); |
Value stored to 'x' during its initialization is never read | |
| 1043 | jint maskbits = t3->get_con(); |
| 1044 | // Convert to "(x >> shift) & (mask >> shift)" |
| 1045 | Node *shr_nomask = phase->transform( new RShiftINode(mask->in(1), in(2)) ); |
| 1046 | return new AndINode(shr_nomask, phase->intcon( maskbits >> shift)); |
| 1047 | } |
| 1048 | |
| 1049 | // Check for "(short[i] <<16)>>16" which simply sign-extends |
| 1050 | const Node *shl = in(1); |
| 1051 | if( shl->Opcode() != Op_LShiftI ) return NULL__null; |
| 1052 | |
| 1053 | if( shift == 16 && |
| 1054 | (t3 = phase->type(shl->in(2))->isa_int()) && |
| 1055 | t3->is_con(16) ) { |
| 1056 | Node *ld = shl->in(1); |
| 1057 | if( ld->Opcode() == Op_LoadS ) { |
| 1058 | // Sign extension is just useless here. Return a RShiftI of zero instead |
| 1059 | // returning 'ld' directly. We cannot return an old Node directly as |
| 1060 | // that is the job of 'Identity' calls and Identity calls only work on |
| 1061 | // direct inputs ('ld' is an extra Node removed from 'this'). The |
| 1062 | // combined optimization requires Identity only return direct inputs. |
| 1063 | set_req_X(1, ld, phase); |
| 1064 | set_req_X(2, phase->intcon(0), phase); |
| 1065 | return this; |
| 1066 | } |
| 1067 | else if (can_reshape && |
| 1068 | ld->Opcode() == Op_LoadUS && |
| 1069 | ld->outcnt() == 1 && ld->unique_out() == shl) |
| 1070 | // Replace zero-extension-load with sign-extension-load |
| 1071 | return ld->as_Load()->convert_to_signed_load(*phase); |
| 1072 | } |
| 1073 | |
| 1074 | // Check for "(byte[i] <<24)>>24" which simply sign-extends |
| 1075 | if( shift == 24 && |
| 1076 | (t3 = phase->type(shl->in(2))->isa_int()) && |
| 1077 | t3->is_con(24) ) { |
| 1078 | Node *ld = shl->in(1); |
| 1079 | if (ld->Opcode() == Op_LoadB) { |
| 1080 | // Sign extension is just useless here |
| 1081 | set_req_X(1, ld, phase); |
| 1082 | set_req_X(2, phase->intcon(0), phase); |
| 1083 | return this; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | return NULL__null; |
| 1088 | } |
| 1089 | |
| 1090 | //------------------------------Value------------------------------------------ |
| 1091 | // A RShiftINode shifts its input2 right by input1 amount. |
| 1092 | const Type* RShiftINode::Value(PhaseGVN* phase) const { |
| 1093 | const Type *t1 = phase->type( in(1) ); |
| 1094 | const Type *t2 = phase->type( in(2) ); |
| 1095 | // Either input is TOP ==> the result is TOP |
| 1096 | if( t1 == Type::TOP ) return Type::TOP; |
| 1097 | if( t2 == Type::TOP ) return Type::TOP; |
| 1098 | |
| 1099 | // Left input is ZERO ==> the result is ZERO. |
| 1100 | if( t1 == TypeInt::ZERO ) return TypeInt::ZERO; |
| 1101 | // Shift by zero does nothing |
| 1102 | if( t2 == TypeInt::ZERO ) return t1; |
| 1103 | |
| 1104 | // Either input is BOTTOM ==> the result is BOTTOM |
| 1105 | if (t1 == Type::BOTTOM || t2 == Type::BOTTOM) |
| 1106 | return TypeInt::INT; |
| 1107 | |
| 1108 | if (t2 == TypeInt::INT) |
| 1109 | return TypeInt::INT; |
| 1110 | |
| 1111 | const TypeInt *r1 = t1->is_int(); // Handy access |
| 1112 | const TypeInt *r2 = t2->is_int(); // Handy access |
| 1113 | |
| 1114 | // If the shift is a constant, just shift the bounds of the type. |
| 1115 | // For example, if the shift is 31, we just propagate sign bits. |
| 1116 | if (r2->is_con()) { |
| 1117 | uint shift = r2->get_con(); |
| 1118 | shift &= BitsPerJavaInteger-1; // semantics of Java shifts |
| 1119 | // Shift by a multiple of 32 does nothing: |
| 1120 | if (shift == 0) return t1; |
| 1121 | // Calculate reasonably aggressive bounds for the result. |
| 1122 | // This is necessary if we are to correctly type things |
| 1123 | // like (x<<24>>24) == ((byte)x). |
| 1124 | jint lo = (jint)r1->_lo >> (jint)shift; |
| 1125 | jint hi = (jint)r1->_hi >> (jint)shift; |
| 1126 | assert(lo <= hi, "must have valid bounds")do { if (!(lo <= hi)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1126, "assert(" "lo <= hi" ") failed", "must have valid bounds" ); ::breakpoint(); } } while (0); |
| 1127 | const TypeInt* ti = TypeInt::make(lo, hi, MAX2(r1->_widen,r2->_widen)); |
| 1128 | #ifdef ASSERT1 |
| 1129 | // Make sure we get the sign-capture idiom correct. |
| 1130 | if (shift == BitsPerJavaInteger-1) { |
| 1131 | if (r1->_lo >= 0) assert(ti == TypeInt::ZERO, ">>31 of + is 0")do { if (!(ti == TypeInt::ZERO)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1131, "assert(" "ti == TypeInt::ZERO" ") failed", ">>31 of + is 0" ); ::breakpoint(); } } while (0); |
| 1132 | if (r1->_hi < 0) assert(ti == TypeInt::MINUS_1, ">>31 of - is -1")do { if (!(ti == TypeInt::MINUS_1)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1132, "assert(" "ti == TypeInt::MINUS_1" ") failed", ">>31 of - is -1" ); ::breakpoint(); } } while (0); |
| 1133 | } |
| 1134 | #endif |
| 1135 | return ti; |
| 1136 | } |
| 1137 | |
| 1138 | if( !r1->is_con() || !r2->is_con() ) |
| 1139 | return TypeInt::INT; |
| 1140 | |
| 1141 | // Signed shift right |
| 1142 | return TypeInt::make( r1->get_con() >> (r2->get_con()&31) ); |
| 1143 | } |
| 1144 | |
| 1145 | //============================================================================= |
| 1146 | //------------------------------Identity--------------------------------------- |
| 1147 | Node* RShiftLNode::Identity(PhaseGVN* phase) { |
| 1148 | const TypeInt *ti = phase->type(in(2))->isa_int(); // Shift count is an int. |
| 1149 | return (ti && ti->is_con() && (ti->get_con() & (BitsPerJavaLong - 1)) == 0) ? in(1) : this; |
| 1150 | } |
| 1151 | |
| 1152 | //------------------------------Value------------------------------------------ |
| 1153 | // A RShiftLNode shifts its input2 right by input1 amount. |
| 1154 | const Type* RShiftLNode::Value(PhaseGVN* phase) const { |
| 1155 | const Type *t1 = phase->type( in(1) ); |
| 1156 | const Type *t2 = phase->type( in(2) ); |
| 1157 | // Either input is TOP ==> the result is TOP |
| 1158 | if( t1 == Type::TOP ) return Type::TOP; |
| 1159 | if( t2 == Type::TOP ) return Type::TOP; |
| 1160 | |
| 1161 | // Left input is ZERO ==> the result is ZERO. |
| 1162 | if( t1 == TypeLong::ZERO ) return TypeLong::ZERO; |
| 1163 | // Shift by zero does nothing |
| 1164 | if( t2 == TypeInt::ZERO ) return t1; |
| 1165 | |
| 1166 | // Either input is BOTTOM ==> the result is BOTTOM |
| 1167 | if (t1 == Type::BOTTOM || t2 == Type::BOTTOM) |
| 1168 | return TypeLong::LONG; |
| 1169 | |
| 1170 | if (t2 == TypeInt::INT) |
| 1171 | return TypeLong::LONG; |
| 1172 | |
| 1173 | const TypeLong *r1 = t1->is_long(); // Handy access |
| 1174 | const TypeInt *r2 = t2->is_int (); // Handy access |
| 1175 | |
| 1176 | // If the shift is a constant, just shift the bounds of the type. |
| 1177 | // For example, if the shift is 63, we just propagate sign bits. |
| 1178 | if (r2->is_con()) { |
| 1179 | uint shift = r2->get_con(); |
| 1180 | shift &= (2*BitsPerJavaInteger)-1; // semantics of Java shifts |
| 1181 | // Shift by a multiple of 64 does nothing: |
| 1182 | if (shift == 0) return t1; |
| 1183 | // Calculate reasonably aggressive bounds for the result. |
| 1184 | // This is necessary if we are to correctly type things |
| 1185 | // like (x<<24>>24) == ((byte)x). |
| 1186 | jlong lo = (jlong)r1->_lo >> (jlong)shift; |
| 1187 | jlong hi = (jlong)r1->_hi >> (jlong)shift; |
| 1188 | assert(lo <= hi, "must have valid bounds")do { if (!(lo <= hi)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1188, "assert(" "lo <= hi" ") failed", "must have valid bounds" ); ::breakpoint(); } } while (0); |
| 1189 | const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen)); |
| 1190 | #ifdef ASSERT1 |
| 1191 | // Make sure we get the sign-capture idiom correct. |
| 1192 | if (shift == (2*BitsPerJavaInteger)-1) { |
| 1193 | if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>63 of + is 0")do { if (!(tl == TypeLong::ZERO)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1193, "assert(" "tl == TypeLong::ZERO" ") failed", ">>63 of + is 0" ); ::breakpoint(); } } while (0); |
| 1194 | if (r1->_hi < 0) assert(tl == TypeLong::MINUS_1, ">>63 of - is -1")do { if (!(tl == TypeLong::MINUS_1)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1194, "assert(" "tl == TypeLong::MINUS_1" ") failed", ">>63 of - is -1" ); ::breakpoint(); } } while (0); |
| 1195 | } |
| 1196 | #endif |
| 1197 | return tl; |
| 1198 | } |
| 1199 | |
| 1200 | return TypeLong::LONG; // Give up |
| 1201 | } |
| 1202 | |
| 1203 | //============================================================================= |
| 1204 | //------------------------------Identity--------------------------------------- |
| 1205 | Node* URShiftINode::Identity(PhaseGVN* phase) { |
| 1206 | int count = 0; |
| 1207 | if (const_shift_count(phase, this, &count) && (count & (BitsPerJavaInteger - 1)) == 0) { |
| 1208 | // Shift by a multiple of 32 does nothing |
| 1209 | return in(1); |
| 1210 | } |
| 1211 | |
| 1212 | // Check for "((x << LogBytesPerWord) + (wordSize-1)) >> LogBytesPerWord" which is just "x". |
| 1213 | // Happens during new-array length computation. |
| 1214 | // Safe if 'x' is in the range [0..(max_int>>LogBytesPerWord)] |
| 1215 | Node *add = in(1); |
| 1216 | if (add->Opcode() == Op_AddI) { |
| 1217 | const TypeInt *t2 = phase->type(add->in(2))->isa_int(); |
| 1218 | if (t2 && t2->is_con(wordSize - 1) && |
| 1219 | add->in(1)->Opcode() == Op_LShiftI) { |
| 1220 | // Check that shift_counts are LogBytesPerWord. |
| 1221 | Node *lshift_count = add->in(1)->in(2); |
| 1222 | const TypeInt *t_lshift_count = phase->type(lshift_count)->isa_int(); |
| 1223 | if (t_lshift_count && t_lshift_count->is_con(LogBytesPerWord) && |
| 1224 | t_lshift_count == phase->type(in(2))) { |
| 1225 | Node *x = add->in(1)->in(1); |
| 1226 | const TypeInt *t_x = phase->type(x)->isa_int(); |
| 1227 | if (t_x != NULL__null && 0 <= t_x->_lo && t_x->_hi <= (max_jint>>LogBytesPerWord)) { |
| 1228 | return x; |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | return (phase->type(in(2))->higher_equal(TypeInt::ZERO)) ? in(1) : this; |
| 1235 | } |
| 1236 | |
| 1237 | //------------------------------Ideal------------------------------------------ |
| 1238 | Node *URShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 1239 | int con = maskShiftAmount(phase, this, BitsPerJavaInteger); |
| 1240 | if (con == 0) { |
| 1241 | return NULL__null; |
| 1242 | } |
| 1243 | |
| 1244 | // We'll be wanting the right-shift amount as a mask of that many bits |
| 1245 | const int mask = right_n_bits(BitsPerJavaInteger - con)((((BitsPerJavaInteger - con) >= BitsPerWord) ? 0 : (OneBit << (BitsPerJavaInteger - con))) - 1); |
| 1246 | |
| 1247 | int in1_op = in(1)->Opcode(); |
| 1248 | |
| 1249 | // Check for ((x>>>a)>>>b) and replace with (x>>>(a+b)) when a+b < 32 |
| 1250 | if( in1_op == Op_URShiftI ) { |
| 1251 | const TypeInt *t12 = phase->type( in(1)->in(2) )->isa_int(); |
| 1252 | if( t12 && t12->is_con() ) { // Right input is a constant |
| 1253 | assert( in(1) != in(1)->in(1), "dead loop in URShiftINode::Ideal" )do { if (!(in(1) != in(1)->in(1))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1253, "assert(" "in(1) != in(1)->in(1)" ") failed", "dead loop in URShiftINode::Ideal" ); ::breakpoint(); } } while (0); |
| 1254 | const int con2 = t12->get_con() & 31; // Shift count is always masked |
| 1255 | const int con3 = con+con2; |
| 1256 | if( con3 < 32 ) // Only merge shifts if total is < 32 |
| 1257 | return new URShiftINode( in(1)->in(1), phase->intcon(con3) ); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | // Check for ((x << z) + Y) >>> z. Replace with x + con>>>z |
| 1262 | // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z". |
| 1263 | // If Q is "X << z" the rounding is useless. Look for patterns like |
| 1264 | // ((X<<Z) + Y) >>> Z and replace with (X + Y>>>Z) & Z-mask. |
| 1265 | Node *add = in(1); |
| 1266 | const TypeInt *t2 = phase->type(in(2))->isa_int(); |
| 1267 | if (in1_op == Op_AddI) { |
| 1268 | Node *lshl = add->in(1); |
| 1269 | if( lshl->Opcode() == Op_LShiftI && |
| 1270 | phase->type(lshl->in(2)) == t2 ) { |
| 1271 | Node *y_z = phase->transform( new URShiftINode(add->in(2),in(2)) ); |
| 1272 | Node *sum = phase->transform( new AddINode( lshl->in(1), y_z ) ); |
| 1273 | return new AndINode( sum, phase->intcon(mask) ); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | // Check for (x & mask) >>> z. Replace with (x >>> z) & (mask >>> z) |
| 1278 | // This shortens the mask. Also, if we are extracting a high byte and |
| 1279 | // storing it to a buffer, the mask will be removed completely. |
| 1280 | Node *andi = in(1); |
| 1281 | if( in1_op == Op_AndI ) { |
| 1282 | const TypeInt *t3 = phase->type( andi->in(2) )->isa_int(); |
| 1283 | if( t3 && t3->is_con() ) { // Right input is a constant |
| 1284 | jint mask2 = t3->get_con(); |
| 1285 | mask2 >>= con; // *signed* shift downward (high-order zeroes do not help) |
| 1286 | Node *newshr = phase->transform( new URShiftINode(andi->in(1), in(2)) ); |
| 1287 | return new AndINode(newshr, phase->intcon(mask2)); |
| 1288 | // The negative values are easier to materialize than positive ones. |
| 1289 | // A typical case from address arithmetic is ((x & ~15) >> 4). |
| 1290 | // It's better to change that to ((x >> 4) & ~0) versus |
| 1291 | // ((x >> 4) & 0x0FFFFFFF). The difference is greatest in LP64. |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | // Check for "(X << z ) >>> z" which simply zero-extends |
| 1296 | Node *shl = in(1); |
| 1297 | if( in1_op == Op_LShiftI && |
| 1298 | phase->type(shl->in(2)) == t2 ) |
| 1299 | return new AndINode( shl->in(1), phase->intcon(mask) ); |
| 1300 | |
| 1301 | // Check for (x >> n) >>> 31. Replace with (x >>> 31) |
| 1302 | Node *shr = in(1); |
| 1303 | if ( in1_op == Op_RShiftI ) { |
| 1304 | Node *in11 = shr->in(1); |
| 1305 | Node *in12 = shr->in(2); |
| 1306 | const TypeInt *t11 = phase->type(in11)->isa_int(); |
| 1307 | const TypeInt *t12 = phase->type(in12)->isa_int(); |
| 1308 | if ( t11 && t2 && t2->is_con(31) && t12 && t12->is_con() ) { |
| 1309 | return new URShiftINode(in11, phase->intcon(31)); |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | return NULL__null; |
| 1314 | } |
| 1315 | |
| 1316 | //------------------------------Value------------------------------------------ |
| 1317 | // A URShiftINode shifts its input2 right by input1 amount. |
| 1318 | const Type* URShiftINode::Value(PhaseGVN* phase) const { |
| 1319 | // (This is a near clone of RShiftINode::Value.) |
| 1320 | const Type *t1 = phase->type( in(1) ); |
| 1321 | const Type *t2 = phase->type( in(2) ); |
| 1322 | // Either input is TOP ==> the result is TOP |
| 1323 | if( t1 == Type::TOP ) return Type::TOP; |
| 1324 | if( t2 == Type::TOP ) return Type::TOP; |
| 1325 | |
| 1326 | // Left input is ZERO ==> the result is ZERO. |
| 1327 | if( t1 == TypeInt::ZERO ) return TypeInt::ZERO; |
| 1328 | // Shift by zero does nothing |
| 1329 | if( t2 == TypeInt::ZERO ) return t1; |
| 1330 | |
| 1331 | // Either input is BOTTOM ==> the result is BOTTOM |
| 1332 | if (t1 == Type::BOTTOM || t2 == Type::BOTTOM) |
| 1333 | return TypeInt::INT; |
| 1334 | |
| 1335 | if (t2 == TypeInt::INT) |
| 1336 | return TypeInt::INT; |
| 1337 | |
| 1338 | const TypeInt *r1 = t1->is_int(); // Handy access |
| 1339 | const TypeInt *r2 = t2->is_int(); // Handy access |
| 1340 | |
| 1341 | if (r2->is_con()) { |
| 1342 | uint shift = r2->get_con(); |
| 1343 | shift &= BitsPerJavaInteger-1; // semantics of Java shifts |
| 1344 | // Shift by a multiple of 32 does nothing: |
| 1345 | if (shift == 0) return t1; |
| 1346 | // Calculate reasonably aggressive bounds for the result. |
| 1347 | jint lo = (juint)r1->_lo >> (juint)shift; |
| 1348 | jint hi = (juint)r1->_hi >> (juint)shift; |
| 1349 | if (r1->_hi >= 0 && r1->_lo < 0) { |
| 1350 | // If the type has both negative and positive values, |
| 1351 | // there are two separate sub-domains to worry about: |
| 1352 | // The positive half and the negative half. |
| 1353 | jint neg_lo = lo; |
| 1354 | jint neg_hi = (juint)-1 >> (juint)shift; |
| 1355 | jint pos_lo = (juint) 0 >> (juint)shift; |
| 1356 | jint pos_hi = hi; |
| 1357 | lo = MIN2(neg_lo, pos_lo); // == 0 |
| 1358 | hi = MAX2(neg_hi, pos_hi); // == -1 >>> shift; |
| 1359 | } |
| 1360 | assert(lo <= hi, "must have valid bounds")do { if (!(lo <= hi)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1360, "assert(" "lo <= hi" ") failed", "must have valid bounds" ); ::breakpoint(); } } while (0); |
| 1361 | const TypeInt* ti = TypeInt::make(lo, hi, MAX2(r1->_widen,r2->_widen)); |
| 1362 | #ifdef ASSERT1 |
| 1363 | // Make sure we get the sign-capture idiom correct. |
| 1364 | if (shift == BitsPerJavaInteger-1) { |
| 1365 | if (r1->_lo >= 0) assert(ti == TypeInt::ZERO, ">>>31 of + is 0")do { if (!(ti == TypeInt::ZERO)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1365, "assert(" "ti == TypeInt::ZERO" ") failed", ">>>31 of + is 0" ); ::breakpoint(); } } while (0); |
| 1366 | if (r1->_hi < 0) assert(ti == TypeInt::ONE, ">>>31 of - is +1")do { if (!(ti == TypeInt::ONE)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1366, "assert(" "ti == TypeInt::ONE" ") failed", ">>>31 of - is +1" ); ::breakpoint(); } } while (0); |
| 1367 | } |
| 1368 | #endif |
| 1369 | return ti; |
| 1370 | } |
| 1371 | |
| 1372 | // |
| 1373 | // Do not support shifted oops in info for GC |
| 1374 | // |
| 1375 | // else if( t1->base() == Type::InstPtr ) { |
| 1376 | // |
| 1377 | // const TypeInstPtr *o = t1->is_instptr(); |
| 1378 | // if( t1->singleton() ) |
| 1379 | // return TypeInt::make( ((uint32_t)o->const_oop() + o->_offset) >> shift ); |
| 1380 | // } |
| 1381 | // else if( t1->base() == Type::KlassPtr ) { |
| 1382 | // const TypeKlassPtr *o = t1->is_klassptr(); |
| 1383 | // if( t1->singleton() ) |
| 1384 | // return TypeInt::make( ((uint32_t)o->const_oop() + o->_offset) >> shift ); |
| 1385 | // } |
| 1386 | |
| 1387 | return TypeInt::INT; |
| 1388 | } |
| 1389 | |
| 1390 | //============================================================================= |
| 1391 | //------------------------------Identity--------------------------------------- |
| 1392 | Node* URShiftLNode::Identity(PhaseGVN* phase) { |
| 1393 | int count = 0; |
| 1394 | if (const_shift_count(phase, this, &count) && (count & (BitsPerJavaLong - 1)) == 0) { |
| 1395 | // Shift by a multiple of 64 does nothing |
| 1396 | return in(1); |
| 1397 | } |
| 1398 | return this; |
| 1399 | } |
| 1400 | |
| 1401 | //------------------------------Ideal------------------------------------------ |
| 1402 | Node *URShiftLNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 1403 | int con = maskShiftAmount(phase, this, BitsPerJavaLong); |
| 1404 | if (con == 0) { |
| 1405 | return NULL__null; |
| 1406 | } |
| 1407 | |
| 1408 | // We'll be wanting the right-shift amount as a mask of that many bits |
| 1409 | const jlong mask = jlong(max_julong >> con); |
| 1410 | |
| 1411 | // Check for ((x << z) + Y) >>> z. Replace with x + con>>>z |
| 1412 | // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z". |
| 1413 | // If Q is "X << z" the rounding is useless. Look for patterns like |
| 1414 | // ((X<<Z) + Y) >>> Z and replace with (X + Y>>>Z) & Z-mask. |
| 1415 | Node *add = in(1); |
| 1416 | const TypeInt *t2 = phase->type(in(2))->isa_int(); |
| 1417 | if (add->Opcode() == Op_AddL) { |
| 1418 | Node *lshl = add->in(1); |
| 1419 | if( lshl->Opcode() == Op_LShiftL && |
| 1420 | phase->type(lshl->in(2)) == t2 ) { |
| 1421 | Node *y_z = phase->transform( new URShiftLNode(add->in(2),in(2)) ); |
| 1422 | Node *sum = phase->transform( new AddLNode( lshl->in(1), y_z ) ); |
| 1423 | return new AndLNode( sum, phase->longcon(mask) ); |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | // Check for (x & mask) >>> z. Replace with (x >>> z) & (mask >>> z) |
| 1428 | // This shortens the mask. Also, if we are extracting a high byte and |
| 1429 | // storing it to a buffer, the mask will be removed completely. |
| 1430 | Node *andi = in(1); |
| 1431 | if( andi->Opcode() == Op_AndL ) { |
| 1432 | const TypeLong *t3 = phase->type( andi->in(2) )->isa_long(); |
| 1433 | if( t3 && t3->is_con() ) { // Right input is a constant |
| 1434 | jlong mask2 = t3->get_con(); |
| 1435 | mask2 >>= con; // *signed* shift downward (high-order zeroes do not help) |
| 1436 | Node *newshr = phase->transform( new URShiftLNode(andi->in(1), in(2)) ); |
| 1437 | return new AndLNode(newshr, phase->longcon(mask2)); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | // Check for "(X << z ) >>> z" which simply zero-extends |
| 1442 | Node *shl = in(1); |
| 1443 | if( shl->Opcode() == Op_LShiftL && |
| 1444 | phase->type(shl->in(2)) == t2 ) |
| 1445 | return new AndLNode( shl->in(1), phase->longcon(mask) ); |
| 1446 | |
| 1447 | // Check for (x >> n) >>> 63. Replace with (x >>> 63) |
| 1448 | Node *shr = in(1); |
| 1449 | if ( shr->Opcode() == Op_RShiftL ) { |
| 1450 | Node *in11 = shr->in(1); |
| 1451 | Node *in12 = shr->in(2); |
| 1452 | const TypeLong *t11 = phase->type(in11)->isa_long(); |
| 1453 | const TypeInt *t12 = phase->type(in12)->isa_int(); |
| 1454 | if ( t11 && t2 && t2->is_con(63) && t12 && t12->is_con() ) { |
| 1455 | return new URShiftLNode(in11, phase->intcon(63)); |
| 1456 | } |
| 1457 | } |
| 1458 | return NULL__null; |
| 1459 | } |
| 1460 | |
| 1461 | //------------------------------Value------------------------------------------ |
| 1462 | // A URShiftINode shifts its input2 right by input1 amount. |
| 1463 | const Type* URShiftLNode::Value(PhaseGVN* phase) const { |
| 1464 | // (This is a near clone of RShiftLNode::Value.) |
| 1465 | const Type *t1 = phase->type( in(1) ); |
| 1466 | const Type *t2 = phase->type( in(2) ); |
| 1467 | // Either input is TOP ==> the result is TOP |
| 1468 | if( t1 == Type::TOP ) return Type::TOP; |
| 1469 | if( t2 == Type::TOP ) return Type::TOP; |
| 1470 | |
| 1471 | // Left input is ZERO ==> the result is ZERO. |
| 1472 | if( t1 == TypeLong::ZERO ) return TypeLong::ZERO; |
| 1473 | // Shift by zero does nothing |
| 1474 | if( t2 == TypeInt::ZERO ) return t1; |
| 1475 | |
| 1476 | // Either input is BOTTOM ==> the result is BOTTOM |
| 1477 | if (t1 == Type::BOTTOM || t2 == Type::BOTTOM) |
| 1478 | return TypeLong::LONG; |
| 1479 | |
| 1480 | if (t2 == TypeInt::INT) |
| 1481 | return TypeLong::LONG; |
| 1482 | |
| 1483 | const TypeLong *r1 = t1->is_long(); // Handy access |
| 1484 | const TypeInt *r2 = t2->is_int (); // Handy access |
| 1485 | |
| 1486 | if (r2->is_con()) { |
| 1487 | uint shift = r2->get_con(); |
| 1488 | shift &= BitsPerJavaLong - 1; // semantics of Java shifts |
| 1489 | // Shift by a multiple of 64 does nothing: |
| 1490 | if (shift == 0) return t1; |
| 1491 | // Calculate reasonably aggressive bounds for the result. |
| 1492 | jlong lo = (julong)r1->_lo >> (juint)shift; |
| 1493 | jlong hi = (julong)r1->_hi >> (juint)shift; |
| 1494 | if (r1->_hi >= 0 && r1->_lo < 0) { |
| 1495 | // If the type has both negative and positive values, |
| 1496 | // there are two separate sub-domains to worry about: |
| 1497 | // The positive half and the negative half. |
| 1498 | jlong neg_lo = lo; |
| 1499 | jlong neg_hi = (julong)-1 >> (juint)shift; |
| 1500 | jlong pos_lo = (julong) 0 >> (juint)shift; |
| 1501 | jlong pos_hi = hi; |
| 1502 | //lo = MIN2(neg_lo, pos_lo); // == 0 |
| 1503 | lo = neg_lo < pos_lo ? neg_lo : pos_lo; |
| 1504 | //hi = MAX2(neg_hi, pos_hi); // == -1 >>> shift; |
| 1505 | hi = neg_hi > pos_hi ? neg_hi : pos_hi; |
| 1506 | } |
| 1507 | assert(lo <= hi, "must have valid bounds")do { if (!(lo <= hi)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1507, "assert(" "lo <= hi" ") failed", "must have valid bounds" ); ::breakpoint(); } } while (0); |
| 1508 | const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen)); |
| 1509 | #ifdef ASSERT1 |
| 1510 | // Make sure we get the sign-capture idiom correct. |
| 1511 | if (shift == BitsPerJavaLong - 1) { |
| 1512 | if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0")do { if (!(tl == TypeLong::ZERO)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1512, "assert(" "tl == TypeLong::ZERO" ") failed", ">>>63 of + is 0" ); ::breakpoint(); } } while (0); |
| 1513 | if (r1->_hi < 0) assert(tl == TypeLong::ONE, ">>>63 of - is +1")do { if (!(tl == TypeLong::ONE)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1513, "assert(" "tl == TypeLong::ONE" ") failed", ">>>63 of - is +1" ); ::breakpoint(); } } while (0); |
| 1514 | } |
| 1515 | #endif |
| 1516 | return tl; |
| 1517 | } |
| 1518 | |
| 1519 | return TypeLong::LONG; // Give up |
| 1520 | } |
| 1521 | |
| 1522 | //============================================================================= |
| 1523 | //------------------------------Value------------------------------------------ |
| 1524 | const Type* FmaDNode::Value(PhaseGVN* phase) const { |
| 1525 | const Type *t1 = phase->type(in(1)); |
| 1526 | if (t1 == Type::TOP) return Type::TOP; |
| 1527 | if (t1->base() != Type::DoubleCon) return Type::DOUBLE; |
| 1528 | const Type *t2 = phase->type(in(2)); |
| 1529 | if (t2 == Type::TOP) return Type::TOP; |
| 1530 | if (t2->base() != Type::DoubleCon) return Type::DOUBLE; |
| 1531 | const Type *t3 = phase->type(in(3)); |
| 1532 | if (t3 == Type::TOP) return Type::TOP; |
| 1533 | if (t3->base() != Type::DoubleCon) return Type::DOUBLE; |
| 1534 | #ifndef __STDC_IEC_559__1 |
| 1535 | return Type::DOUBLE; |
| 1536 | #else |
| 1537 | double d1 = t1->getd(); |
| 1538 | double d2 = t2->getd(); |
| 1539 | double d3 = t3->getd(); |
| 1540 | return TypeD::make(fma(d1, d2, d3)); |
| 1541 | #endif |
| 1542 | } |
| 1543 | |
| 1544 | //============================================================================= |
| 1545 | //------------------------------Value------------------------------------------ |
| 1546 | const Type* FmaFNode::Value(PhaseGVN* phase) const { |
| 1547 | const Type *t1 = phase->type(in(1)); |
| 1548 | if (t1 == Type::TOP) return Type::TOP; |
| 1549 | if (t1->base() != Type::FloatCon) return Type::FLOAT; |
| 1550 | const Type *t2 = phase->type(in(2)); |
| 1551 | if (t2 == Type::TOP) return Type::TOP; |
| 1552 | if (t2->base() != Type::FloatCon) return Type::FLOAT; |
| 1553 | const Type *t3 = phase->type(in(3)); |
| 1554 | if (t3 == Type::TOP) return Type::TOP; |
| 1555 | if (t3->base() != Type::FloatCon) return Type::FLOAT; |
| 1556 | #ifndef __STDC_IEC_559__1 |
| 1557 | return Type::FLOAT; |
| 1558 | #else |
| 1559 | float f1 = t1->getf(); |
| 1560 | float f2 = t2->getf(); |
| 1561 | float f3 = t3->getf(); |
| 1562 | return TypeF::make(fma(f1, f2, f3)); |
| 1563 | #endif |
| 1564 | } |
| 1565 | |
| 1566 | //============================================================================= |
| 1567 | //------------------------------hash------------------------------------------- |
| 1568 | // Hash function for MulAddS2INode. Operation is commutative with commutative pairs. |
| 1569 | // The hash function must return the same value when edge swapping is performed. |
| 1570 | uint MulAddS2INode::hash() const { |
| 1571 | return (uintptr_t)in(1) + (uintptr_t)in(2) + (uintptr_t)in(3) + (uintptr_t)in(4) + Opcode(); |
| 1572 | } |
| 1573 | |
| 1574 | //------------------------------Rotate Operations ------------------------------ |
| 1575 | |
| 1576 | Node* RotateLeftNode::Identity(PhaseGVN* phase) { |
| 1577 | const Type* t1 = phase->type(in(1)); |
| 1578 | if (t1 == Type::TOP) { |
| 1579 | return this; |
| 1580 | } |
| 1581 | int count = 0; |
| 1582 | assert(t1->isa_int() || t1->isa_long(), "Unexpected type")do { if (!(t1->isa_int() || t1->isa_long())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1582, "assert(" "t1->isa_int() || t1->isa_long()" ") failed" , "Unexpected type"); ::breakpoint(); } } while (0); |
| 1583 | int mask = (t1->isa_int() ? BitsPerJavaInteger : BitsPerJavaLong) - 1; |
| 1584 | if (const_shift_count(phase, this, &count) && (count & mask) == 0) { |
| 1585 | // Rotate by a multiple of 32/64 does nothing |
| 1586 | return in(1); |
| 1587 | } |
| 1588 | return this; |
| 1589 | } |
| 1590 | |
| 1591 | const Type* RotateLeftNode::Value(PhaseGVN* phase) const { |
| 1592 | const Type* t1 = phase->type(in(1)); |
| 1593 | const Type* t2 = phase->type(in(2)); |
| 1594 | // Either input is TOP ==> the result is TOP |
| 1595 | if (t1 == Type::TOP || t2 == Type::TOP) { |
| 1596 | return Type::TOP; |
| 1597 | } |
| 1598 | |
| 1599 | if (t1->isa_int()) { |
| 1600 | const TypeInt* r1 = t1->is_int(); |
| 1601 | const TypeInt* r2 = t2->is_int(); |
| 1602 | |
| 1603 | // Left input is ZERO ==> the result is ZERO. |
| 1604 | if (r1 == TypeInt::ZERO) { |
| 1605 | return TypeInt::ZERO; |
| 1606 | } |
| 1607 | // Rotate by zero does nothing |
| 1608 | if (r2 == TypeInt::ZERO) { |
| 1609 | return r1; |
| 1610 | } |
| 1611 | if (r1->is_con() && r2->is_con()) { |
| 1612 | juint r1_con = (juint)r1->get_con(); |
| 1613 | juint shift = (juint)(r2->get_con()) & (juint)(BitsPerJavaInteger - 1); // semantics of Java shifts |
| 1614 | return TypeInt::make((r1_con << shift) | (r1_con >> (32 - shift))); |
| 1615 | } |
| 1616 | return TypeInt::INT; |
| 1617 | } else { |
| 1618 | assert(t1->isa_long(), "Type must be a long")do { if (!(t1->isa_long())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1618, "assert(" "t1->isa_long()" ") failed", "Type must be a long" ); ::breakpoint(); } } while (0); |
| 1619 | const TypeLong* r1 = t1->is_long(); |
| 1620 | const TypeInt* r2 = t2->is_int(); |
| 1621 | |
| 1622 | // Left input is ZERO ==> the result is ZERO. |
| 1623 | if (r1 == TypeLong::ZERO) { |
| 1624 | return TypeLong::ZERO; |
| 1625 | } |
| 1626 | // Rotate by zero does nothing |
| 1627 | if (r2 == TypeInt::ZERO) { |
| 1628 | return r1; |
| 1629 | } |
| 1630 | if (r1->is_con() && r2->is_con()) { |
| 1631 | julong r1_con = (julong)r1->get_con(); |
| 1632 | julong shift = (julong)(r2->get_con()) & (julong)(BitsPerJavaLong - 1); // semantics of Java shifts |
| 1633 | return TypeLong::make((r1_con << shift) | (r1_con >> (64 - shift))); |
| 1634 | } |
| 1635 | return TypeLong::LONG; |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | Node* RotateLeftNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
| 1640 | const Type* t1 = phase->type(in(1)); |
| 1641 | const Type* t2 = phase->type(in(2)); |
| 1642 | if (t2->isa_int() && t2->is_int()->is_con()) { |
| 1643 | if (t1->isa_int()) { |
| 1644 | int lshift = t2->is_int()->get_con() & 31; |
| 1645 | return new RotateRightNode(in(1), phase->intcon(32 - (lshift & 31)), TypeInt::INT); |
| 1646 | } else if (t1 != Type::TOP) { |
| 1647 | assert(t1->isa_long(), "Type must be a long")do { if (!(t1->isa_long())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1647, "assert(" "t1->isa_long()" ") failed", "Type must be a long" ); ::breakpoint(); } } while (0); |
| 1648 | int lshift = t2->is_int()->get_con() & 63; |
| 1649 | return new RotateRightNode(in(1), phase->intcon(64 - (lshift & 63)), TypeLong::LONG); |
| 1650 | } |
| 1651 | } |
| 1652 | return NULL__null; |
| 1653 | } |
| 1654 | |
| 1655 | Node* RotateRightNode::Identity(PhaseGVN* phase) { |
| 1656 | const Type* t1 = phase->type(in(1)); |
| 1657 | if (t1 == Type::TOP) { |
| 1658 | return this; |
| 1659 | } |
| 1660 | int count = 0; |
| 1661 | assert(t1->isa_int() || t1->isa_long(), "Unexpected type")do { if (!(t1->isa_int() || t1->isa_long())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1661, "assert(" "t1->isa_int() || t1->isa_long()" ") failed" , "Unexpected type"); ::breakpoint(); } } while (0); |
| 1662 | int mask = (t1->isa_int() ? BitsPerJavaInteger : BitsPerJavaLong) - 1; |
| 1663 | if (const_shift_count(phase, this, &count) && (count & mask) == 0) { |
| 1664 | // Rotate by a multiple of 32/64 does nothing |
| 1665 | return in(1); |
| 1666 | } |
| 1667 | return this; |
| 1668 | } |
| 1669 | |
| 1670 | const Type* RotateRightNode::Value(PhaseGVN* phase) const { |
| 1671 | const Type* t1 = phase->type(in(1)); |
| 1672 | const Type* t2 = phase->type(in(2)); |
| 1673 | // Either input is TOP ==> the result is TOP |
| 1674 | if (t1 == Type::TOP || t2 == Type::TOP) { |
| 1675 | return Type::TOP; |
| 1676 | } |
| 1677 | |
| 1678 | if (t1->isa_int()) { |
| 1679 | const TypeInt* r1 = t1->is_int(); |
| 1680 | const TypeInt* r2 = t2->is_int(); |
| 1681 | |
| 1682 | // Left input is ZERO ==> the result is ZERO. |
| 1683 | if (r1 == TypeInt::ZERO) { |
| 1684 | return TypeInt::ZERO; |
| 1685 | } |
| 1686 | // Rotate by zero does nothing |
| 1687 | if (r2 == TypeInt::ZERO) { |
| 1688 | return r1; |
| 1689 | } |
| 1690 | if (r1->is_con() && r2->is_con()) { |
| 1691 | juint r1_con = (juint)r1->get_con(); |
| 1692 | juint shift = (juint)(r2->get_con()) & (juint)(BitsPerJavaInteger - 1); // semantics of Java shifts |
| 1693 | return TypeInt::make((r1_con >> shift) | (r1_con << (32 - shift))); |
| 1694 | } |
| 1695 | return TypeInt::INT; |
| 1696 | } else { |
| 1697 | assert(t1->isa_long(), "Type must be a long")do { if (!(t1->isa_long())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/mulnode.cpp" , 1697, "assert(" "t1->isa_long()" ") failed", "Type must be a long" ); ::breakpoint(); } } while (0); |
| 1698 | const TypeLong* r1 = t1->is_long(); |
| 1699 | const TypeInt* r2 = t2->is_int(); |
| 1700 | // Left input is ZERO ==> the result is ZERO. |
| 1701 | if (r1 == TypeLong::ZERO) { |
| 1702 | return TypeLong::ZERO; |
| 1703 | } |
| 1704 | // Rotate by zero does nothing |
| 1705 | if (r2 == TypeInt::ZERO) { |
| 1706 | return r1; |
| 1707 | } |
| 1708 | if (r1->is_con() && r2->is_con()) { |
| 1709 | julong r1_con = (julong)r1->get_con(); |
| 1710 | julong shift = (julong)(r2->get_con()) & (julong)(BitsPerJavaLong - 1); // semantics of Java shifts |
| 1711 | return TypeLong::make((r1_con >> shift) | (r1_con << (64 - shift))); |
| 1712 | } |
| 1713 | return TypeLong::LONG; |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | // Helper method to transform: |
| 1718 | // patterns similar to (v << 2) & 3 to 0 |
| 1719 | // and |
| 1720 | // patterns similar to (v1 + (v2 << 2)) & 3 transformed to v1 & 3 |
| 1721 | bool MulNode::AndIL_shift_and_mask(PhaseGVN* phase, Node* mask, Node* shift, BasicType bt) { |
| 1722 | if (mask == NULL__null || shift == NULL__null) { |
| 1723 | return false; |
| 1724 | } |
| 1725 | const TypeInteger* mask_t = phase->type(mask)->isa_integer(bt); |
| 1726 | const TypeInteger* shift_t = phase->type(shift)->isa_integer(bt); |
| 1727 | if (mask_t == NULL__null || shift_t == NULL__null) { |
| 1728 | return false; |
| 1729 | } |
| 1730 | if (bt == T_LONG && shift != NULL__null && shift->Opcode() == Op_ConvI2L) { |
| 1731 | bt = T_INT; |
| 1732 | shift = shift->in(1); |
| 1733 | if (shift == NULL__null) { |
| 1734 | return false; |
| 1735 | } |
| 1736 | } |
| 1737 | if (shift->Opcode() != Op_LShift(bt)) { |
| 1738 | return false; |
| 1739 | } |
| 1740 | Node* shift2 = shift->in(2); |
| 1741 | if (shift2 == NULL__null) { |
| 1742 | return false; |
| 1743 | } |
| 1744 | const Type* shift2_t = phase->type(shift2); |
| 1745 | if (!shift2_t->isa_int() || !shift2_t->is_int()->is_con()) { |
| 1746 | return false; |
| 1747 | } |
| 1748 | |
| 1749 | jint shift_con = shift2_t->is_int()->get_con() & ((bt == T_INT ? BitsPerJavaInteger : BitsPerJavaLong) - 1); |
| 1750 | if ((((jlong)1) << shift_con) > mask_t->hi_as_long() && mask_t->lo_as_long() >= 0) { |
| 1751 | return true; |
| 1752 | } |
| 1753 | |
| 1754 | return false; |
| 1755 | } |
| 1756 | |
| 1757 | // Helper method to transform: |
| 1758 | // patterns similar to (v1 + (v2 << 2)) & 3 to v1 & 3 |
| 1759 | Node* MulNode::AndIL_add_shift_and_mask(PhaseGVN* phase, BasicType bt) { |
| 1760 | Node* in1 = in(1); |
| 1761 | Node* in2 = in(2); |
| 1762 | if (in1 != NULL__null && in2 != NULL__null && in1->Opcode() == Op_Add(bt)) { |
| 1763 | Node* add1 = in1->in(1); |
| 1764 | Node* add2 = in1->in(2); |
| 1765 | if (add1 != NULL__null && add2 != NULL__null) { |
| 1766 | if (AndIL_shift_and_mask(phase, in2, add1, bt)) { |
| 1767 | set_req_X(1, add2, phase); |
| 1768 | return this; |
| 1769 | } else if (AndIL_shift_and_mask(phase, in2, add2, bt)) { |
| 1770 | set_req_X(1, add1, phase); |
| 1771 | return this; |
| 1772 | } |
| 1773 | } |
| 1774 | } |
| 1775 | return NULL__null; |
| 1776 | } |