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/memnode.hpp" 30 #include "opto/mulnode.hpp" 31 #include "opto/phaseX.hpp" 32 #include "opto/subnode.hpp" 33 34 // Portions of code courtesy of Clifford Click 35 36 37 //============================================================================= 38 //------------------------------hash------------------------------------------- 39 // Hash function over MulNodes. Needs to be commutative; i.e., I swap 40 // (commute) inputs to MulNodes willy-nilly so the hash function must return 41 // the same value in the presence of edge swapping. 42 uint MulNode::hash() const { 43 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode(); 44 } 45 46 //------------------------------Identity--------------------------------------- 47 // Multiplying a one preserves the other argument 48 Node *MulNode::Identity( PhaseTransform *phase ) { 49 register const Type *one = mul_id(); // The multiplicative identity 50 if( phase->type( in(1) )->higher_equal( one ) ) return in(2); 51 if( phase->type( in(2) )->higher_equal( one ) ) return in(1); 52 455 if (t12 && t12->is_con()) { // Shift is by a constant 456 int shift = t12->get_con(); 457 shift &= BitsPerJavaInteger - 1; // semantics of Java shifts 458 int mask = max_juint >> shift; 459 if ((mask & con) == mask) // If AND is useless, skip it 460 return in1; 461 } 462 } 463 } 464 return MulNode::Identity(phase); 465 } 466 467 //------------------------------Ideal------------------------------------------ 468 Node *AndINode::Ideal(PhaseGVN *phase, bool can_reshape) { 469 // Special case constant AND mask 470 const TypeInt *t2 = phase->type( in(2) )->isa_int(); 471 if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape); 472 const int mask = t2->get_con(); 473 Node *load = in(1); 474 uint lop = load->Opcode(); 475 476 // Masking bits off of a Character? Hi bits are already zero. 477 if( lop == Op_LoadUS && 478 (mask & 0xFFFF0000) ) // Can we make a smaller mask? 479 return new (phase->C) AndINode(load,phase->intcon(mask&0xFFFF)); 480 481 // Masking bits off of a Short? Loading a Character does some masking 482 if (can_reshape && 483 load->outcnt() == 1 && load->unique_out() == this) { 484 if (lop == Op_LoadS && (mask & 0xFFFF0000) == 0 ) { 485 Node *ldus = new (phase->C) LoadUSNode(load->in(MemNode::Control), 486 load->in(MemNode::Memory), 487 load->in(MemNode::Address), 488 load->adr_type(), 489 TypeInt::CHAR, MemNode::unordered); 490 ldus = phase->transform(ldus); 491 return new (phase->C) AndINode(ldus, phase->intcon(mask & 0xFFFF)); 492 } 493 494 // Masking sign bits off of a Byte? Do an unsigned byte load plus | 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/memnode.hpp" 30 #include "opto/mulnode.hpp" 31 #include "opto/phaseX.hpp" 32 #include "opto/subnode.hpp" 33 #include "utilities/macros.hpp" 34 #if INCLUDE_ALL_GCS 35 #include "gc_implementation/shenandoah/c2/shenandoahSupport.hpp" 36 #endif 37 38 // Portions of code courtesy of Clifford Click 39 40 41 //============================================================================= 42 //------------------------------hash------------------------------------------- 43 // Hash function over MulNodes. Needs to be commutative; i.e., I swap 44 // (commute) inputs to MulNodes willy-nilly so the hash function must return 45 // the same value in the presence of edge swapping. 46 uint MulNode::hash() const { 47 return (uintptr_t)in(1) + (uintptr_t)in(2) + Opcode(); 48 } 49 50 //------------------------------Identity--------------------------------------- 51 // Multiplying a one preserves the other argument 52 Node *MulNode::Identity( PhaseTransform *phase ) { 53 register const Type *one = mul_id(); // The multiplicative identity 54 if( phase->type( in(1) )->higher_equal( one ) ) return in(2); 55 if( phase->type( in(2) )->higher_equal( one ) ) return in(1); 56 459 if (t12 && t12->is_con()) { // Shift is by a constant 460 int shift = t12->get_con(); 461 shift &= BitsPerJavaInteger - 1; // semantics of Java shifts 462 int mask = max_juint >> shift; 463 if ((mask & con) == mask) // If AND is useless, skip it 464 return in1; 465 } 466 } 467 } 468 return MulNode::Identity(phase); 469 } 470 471 //------------------------------Ideal------------------------------------------ 472 Node *AndINode::Ideal(PhaseGVN *phase, bool can_reshape) { 473 // Special case constant AND mask 474 const TypeInt *t2 = phase->type( in(2) )->isa_int(); 475 if( !t2 || !t2->is_con() ) return MulNode::Ideal(phase, can_reshape); 476 const int mask = t2->get_con(); 477 Node *load = in(1); 478 uint lop = load->Opcode(); 479 480 #if INCLUDE_ALL_GCS 481 if (UseShenandoahGC && ShenandoahBarrierC2Support::is_gc_state_load(load)) { 482 // Do not touch the load+mask, we would match the whole sequence exactly. 483 // Converting the load to LoadUB/LoadUS would mismatch and waste a register 484 // on the barrier fastpath. 485 return NULL; 486 } 487 #endif 488 489 // Masking bits off of a Character? Hi bits are already zero. 490 if( lop == Op_LoadUS && 491 (mask & 0xFFFF0000) ) // Can we make a smaller mask? 492 return new (phase->C) AndINode(load,phase->intcon(mask&0xFFFF)); 493 494 // Masking bits off of a Short? Loading a Character does some masking 495 if (can_reshape && 496 load->outcnt() == 1 && load->unique_out() == this) { 497 if (lop == Op_LoadS && (mask & 0xFFFF0000) == 0 ) { 498 Node *ldus = new (phase->C) LoadUSNode(load->in(MemNode::Control), 499 load->in(MemNode::Memory), 500 load->in(MemNode::Address), 501 load->adr_type(), 502 TypeInt::CHAR, MemNode::unordered); 503 ldus = phase->transform(ldus); 504 return new (phase->C) AndINode(ldus, phase->intcon(mask & 0xFFFF)); 505 } 506 507 // Masking sign bits off of a Byte? Do an unsigned byte load plus |