comparison src/share/vm/opto/mulnode.cpp @ 559:7628781568e1

6795362: 32bit server compiler leads to wrong results on solaris-x86 Summary: The C2 compiler leads to wrong results on solaris-i486 (32-bit) for a testcase given in the CR. Reviewed-by: never, rasbold
author twisti
date Tue, 03 Feb 2009 01:39:12 -0800
parents 3b5ac9e7e6ea
children 337400e7a5dd
comparison
equal deleted inserted replaced
558:3b5ac9e7e6ea 559:7628781568e1
1 /* 1 /*
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
447 return load; 447 return load;
448 // Masking off the high bits of a unsigned-shift-right is not 448 // Masking off the high bits of a unsigned-shift-right is not
449 // needed either. 449 // needed either.
450 if( lop == Op_URShiftI ) { 450 if( lop == Op_URShiftI ) {
451 const TypeInt *t12 = phase->type( load->in(2) )->isa_int(); 451 const TypeInt *t12 = phase->type( load->in(2) )->isa_int();
452 if( t12 && t12->is_con() ) { 452 if( t12 && t12->is_con() ) { // Shift is by a constant
453 int shift_con = t12->get_con(); 453 int shift = t12->get_con();
454 int mask = max_juint >> shift_con; 454 shift &= BitsPerJavaInteger - 1; // semantics of Java shifts
455 int mask = max_juint >> shift;
455 if( (mask&con) == mask ) // If AND is useless, skip it 456 if( (mask&con) == mask ) // If AND is useless, skip it
456 return load; 457 return load;
457 } 458 }
458 } 459 }
459 } 460 }
577 uint lop = usr->Opcode(); 578 uint lop = usr->Opcode();
578 // Masking off the high bits of a unsigned-shift-right is not 579 // Masking off the high bits of a unsigned-shift-right is not
579 // needed either. 580 // needed either.
580 if( lop == Op_URShiftL ) { 581 if( lop == Op_URShiftL ) {
581 const TypeInt *t12 = phase->type( usr->in(2) )->isa_int(); 582 const TypeInt *t12 = phase->type( usr->in(2) )->isa_int();
582 if( t12 && t12->is_con() ) { 583 if( t12 && t12->is_con() ) { // Shift is by a constant
583 int shift_con = t12->get_con(); 584 int shift = t12->get_con();
584 jlong mask = max_julong >> shift_con; 585 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
586 jlong mask = max_julong >> shift;
585 if( (mask&con) == mask ) // If AND is useless, skip it 587 if( (mask&con) == mask ) // If AND is useless, skip it
586 return usr; 588 return usr;
587 } 589 }
588 } 590 }
589 } 591 }
603 // Masking off sign bits? Dont make them! 605 // Masking off sign bits? Dont make them!
604 if( rop == Op_RShiftL ) { 606 if( rop == Op_RShiftL ) {
605 const TypeInt *t12 = phase->type(rsh->in(2))->isa_int(); 607 const TypeInt *t12 = phase->type(rsh->in(2))->isa_int();
606 if( t12 && t12->is_con() ) { // Shift is by a constant 608 if( t12 && t12->is_con() ) { // Shift is by a constant
607 int shift = t12->get_con(); 609 int shift = t12->get_con();
608 shift &= (BitsPerJavaInteger*2)-1; // semantics of Java shifts 610 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
609 const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - shift)) -1); 611 const jlong sign_bits_mask = ~(((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - shift)) -1);
610 // If the AND'ing of the 2 masks has no bits, then only original shifted 612 // If the AND'ing of the 2 masks has no bits, then only original shifted
611 // bits survive. NO sign-extension bits survive the maskings. 613 // bits survive. NO sign-extension bits survive the maskings.
612 if( (sign_bits_mask & mask) == 0 ) { 614 if( (sign_bits_mask & mask) == 0 ) {
613 // Use zero-fill shift instead 615 // Use zero-fill shift instead
614 Node *zshift = phase->transform(new (phase->C, 3) URShiftLNode(rsh->in(1),rsh->in(2))); 616 Node *zshift = phase->transform(new (phase->C, 3) URShiftLNode(rsh->in(1),rsh->in(2)));
784 } 786 }
785 } 787 }
786 788
787 // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits 789 // Check for ((x & ((CONST64(1)<<(64-c0))-1)) << c0) which ANDs off high bits
788 // before shifting them away. 790 // before shifting them away.
789 const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) - CONST64(1); 791 const jlong bits_mask = ((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) - CONST64(1);
790 if( add1_op == Op_AndL && 792 if( add1_op == Op_AndL &&
791 phase->type(add1->in(2)) == TypeLong::make( bits_mask ) ) 793 phase->type(add1->in(2)) == TypeLong::make( bits_mask ) )
792 return new (phase->C, 3) LShiftLNode( add1->in(1), in(2) ); 794 return new (phase->C, 3) LShiftLNode( add1->in(1), in(2) );
793 795
794 return NULL; 796 return NULL;
818 820
819 if (!r2->is_con()) 821 if (!r2->is_con())
820 return TypeLong::LONG; 822 return TypeLong::LONG;
821 823
822 uint shift = r2->get_con(); 824 uint shift = r2->get_con();
823 shift &= (BitsPerJavaInteger*2)-1; // semantics of Java shifts 825 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
824 // Shift by a multiple of 64 does nothing: 826 // Shift by a multiple of 64 does nothing:
825 if (shift == 0) return t1; 827 if (shift == 0) return t1;
826 828
827 // If the shift is a constant, shift the bounds of the type, 829 // If the shift is a constant, shift the bounds of the type,
828 // unless this could lead to an overflow. 830 // unless this could lead to an overflow.
1233 if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant 1235 if( !t2 || !t2->is_con() ) return NULL; // Right input is a constant
1234 const int con = t2->get_con() & ( BitsPerLong - 1 ); // Shift count is always masked 1236 const int con = t2->get_con() & ( BitsPerLong - 1 ); // Shift count is always masked
1235 if ( con == 0 ) return NULL; // let Identity() handle a 0 shift count 1237 if ( con == 0 ) return NULL; // let Identity() handle a 0 shift count
1236 // note: mask computation below does not work for 0 shift count 1238 // note: mask computation below does not work for 0 shift count
1237 // We'll be wanting the right-shift amount as a mask of that many bits 1239 // We'll be wanting the right-shift amount as a mask of that many bits
1238 const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaInteger*2 - con)) -1); 1240 const jlong mask = (((jlong)CONST64(1) << (jlong)(BitsPerJavaLong - con)) -1);
1239 1241
1240 // Check for ((x << z) + Y) >>> z. Replace with x + con>>>z 1242 // Check for ((x << z) + Y) >>> z. Replace with x + con>>>z
1241 // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z". 1243 // The idiom for rounding to a power of 2 is "(Q+(2^z-1)) >>> z".
1242 // If Q is "X << z" the rounding is useless. Look for patterns like 1244 // If Q is "X << z" the rounding is useless. Look for patterns like
1243 // ((X<<Z) + Y) >>> Z and replace with (X + Y>>>Z) & Z-mask. 1245 // ((X<<Z) + Y) >>> Z and replace with (X + Y>>>Z) & Z-mask.
1300 const TypeLong *r1 = t1->is_long(); // Handy access 1302 const TypeLong *r1 = t1->is_long(); // Handy access
1301 const TypeInt *r2 = t2->is_int (); // Handy access 1303 const TypeInt *r2 = t2->is_int (); // Handy access
1302 1304
1303 if (r2->is_con()) { 1305 if (r2->is_con()) {
1304 uint shift = r2->get_con(); 1306 uint shift = r2->get_con();
1305 shift &= (2*BitsPerJavaInteger)-1; // semantics of Java shifts 1307 shift &= BitsPerJavaLong - 1; // semantics of Java shifts
1306 // Shift by a multiple of 64 does nothing: 1308 // Shift by a multiple of 64 does nothing:
1307 if (shift == 0) return t1; 1309 if (shift == 0) return t1;
1308 // Calculate reasonably aggressive bounds for the result. 1310 // Calculate reasonably aggressive bounds for the result.
1309 jlong lo = (julong)r1->_lo >> (juint)shift; 1311 jlong lo = (julong)r1->_lo >> (juint)shift;
1310 jlong hi = (julong)r1->_hi >> (juint)shift; 1312 jlong hi = (julong)r1->_hi >> (juint)shift;
1323 } 1325 }
1324 assert(lo <= hi, "must have valid bounds"); 1326 assert(lo <= hi, "must have valid bounds");
1325 const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen)); 1327 const TypeLong* tl = TypeLong::make(lo, hi, MAX2(r1->_widen,r2->_widen));
1326 #ifdef ASSERT 1328 #ifdef ASSERT
1327 // Make sure we get the sign-capture idiom correct. 1329 // Make sure we get the sign-capture idiom correct.
1328 if (shift == (2*BitsPerJavaInteger)-1) { 1330 if (shift == BitsPerJavaLong - 1) {
1329 if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0"); 1331 if (r1->_lo >= 0) assert(tl == TypeLong::ZERO, ">>>63 of + is 0");
1330 if (r1->_hi < 0) assert(tl == TypeLong::ONE, ">>>63 of - is +1"); 1332 if (r1->_hi < 0) assert(tl == TypeLong::ONE, ">>>63 of - is +1");
1331 } 1333 }
1332 #endif 1334 #endif
1333 return tl; 1335 return tl;