@@ -225,6 +225,18 @@ MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
225
225
return nullptr ;
226
226
}
227
227
228
+ MulNode* MulNode::make_and (Node* in1, Node* in2, BasicType bt) {
229
+ switch (bt) {
230
+ case T_INT:
231
+ return new AndINode (in1, in2);
232
+ case T_LONG:
233
+ return new AndLNode (in1, in2);
234
+ default :
235
+ fatal (" Not implemented for %s" , type2name (bt));
236
+ }
237
+ return nullptr ;
238
+ }
239
+
228
240
229
241
// =============================================================================
230
242
// ------------------------------Ideal------------------------------------------
@@ -949,7 +961,7 @@ static bool const_shift_count(PhaseGVN* phase, Node* shiftNode, int* count) {
949
961
return false ;
950
962
}
951
963
952
- static int maskShiftAmount (PhaseGVN* phase, Node* shiftNode, int nBits) {
964
+ static int maskShiftAmount (PhaseGVN* phase, Node* shiftNode, uint nBits) {
953
965
int count = 0 ;
954
966
if (const_shift_count (phase, shiftNode, &count)) {
955
967
int maskedShift = count & (nBits - 1 );
@@ -1378,69 +1390,105 @@ const Type* LShiftLNode::Value(PhaseGVN* phase) const {
1378
1390
return TypeLong::make ( (jlong)r1->get_con () << (jint)shift );
1379
1391
}
1380
1392
1393
+ RShiftNode* RShiftNode::make (Node* in1, Node* in2, BasicType bt) {
1394
+ switch (bt) {
1395
+ case T_INT:
1396
+ return new RShiftINode (in1, in2);
1397
+ case T_LONG:
1398
+ return new RShiftLNode (in1, in2);
1399
+ default :
1400
+ fatal (" Not implemented for %s" , type2name (bt));
1401
+ }
1402
+ return nullptr ;
1403
+ }
1404
+
1405
+
1381
1406
// =============================================================================
1382
1407
// ------------------------------Identity---------------------------------------
1383
- Node* RShiftINode::Identity (PhaseGVN* phase) {
1408
+ Node* RShiftNode::IdentityIL (PhaseGVN* phase, BasicType bt ) {
1384
1409
int count = 0 ;
1385
1410
if (const_shift_count (phase, this , &count)) {
1386
- if ((count & (BitsPerJavaInteger - 1 )) == 0 ) {
1387
- // Shift by a multiple of 32 does nothing
1411
+ if ((count & (bits_per_java_integer (bt) - 1 )) == 0 ) {
1412
+ // Shift by a multiple of 32/64 does nothing
1388
1413
return in (1 );
1389
1414
}
1390
1415
// Check for useless sign-masking
1391
- if (in (1 )->Opcode () == Op_LShiftI &&
1416
+ if (in (1 )->Opcode () == Op_LShift (bt) &&
1392
1417
in (1 )->req () == 3 &&
1393
1418
in (1 )->in (2 ) == in (2 )) {
1394
- count &= BitsPerJavaInteger- 1 ; // semantics of Java shifts
1419
+ count &= bits_per_java_integer (bt) - 1 ; // semantics of Java shifts
1395
1420
// Compute masks for which this shifting doesn't change
1396
- int lo = (- 1 << (BitsPerJavaInteger - ((uint)count)-1 )); // FFFF8000
1397
- int hi = ~lo; // 00007FFF
1398
- const TypeInt * t11 = phase->type (in (1 )->in (1 ))->isa_int ( );
1421
+ jlong lo = (CONST64 (- 1 ) << (bits_per_java_integer (bt) - ((uint)count)-1 )); // FFFF8000
1422
+ jlong hi = ~lo; // 00007FFF
1423
+ const TypeInteger * t11 = phase->type (in (1 )->in (1 ))->isa_integer (bt );
1399
1424
if (t11 == nullptr ) {
1400
1425
return this ;
1401
1426
}
1402
1427
// Does actual value fit inside of mask?
1403
- if (lo <= t11->_lo && t11->_hi <= hi) {
1428
+ if (lo <= t11->lo_as_long () && t11->hi_as_long () <= hi) {
1404
1429
return in (1 )->in (1 ); // Then shifting is a nop
1405
1430
}
1406
1431
}
1407
1432
}
1408
1433
return this ;
1409
1434
}
1410
1435
1411
- // ------------------------------Ideal------------------------------------------
1412
- Node *RShiftINode::Ideal (PhaseGVN *phase, bool can_reshape) {
1436
+ Node* RShiftINode::Identity (PhaseGVN* phase) {
1437
+ return IdentityIL (phase, T_INT);
1438
+ }
1439
+
1440
+ Node* RShiftNode::IdealIL (PhaseGVN* phase, bool can_reshape, BasicType bt) {
1413
1441
// Inputs may be TOP if they are dead.
1414
- const TypeInt *t1 = phase->type (in (1 ))->isa_int ();
1415
- if (!t1) return nullptr ; // Left input is an integer
1416
- const TypeInt *t3; // type of in(1).in(2)
1417
- int shift = maskShiftAmount (phase, this , BitsPerJavaInteger);
1442
+ const TypeInteger* t1 = phase->type (in (1 ))->isa_integer (bt);
1443
+ if (t1 == nullptr ) {
1444
+ return NodeSentinel; // Left input is an integer
1445
+ }
1446
+ int shift = maskShiftAmount (phase, this , bits_per_java_integer (bt));
1418
1447
if (shift == 0 ) {
1419
- return nullptr ;
1448
+ return NodeSentinel ;
1420
1449
}
1421
1450
1422
1451
// Check for (x & 0xFF000000) >> 24, whose mask can be made smaller.
1452
+ // and convert to (x >> 24) & (0xFF000000 >> 24) = x >> 24
1423
1453
// Such expressions arise normally from shift chains like (byte)(x >> 24).
1424
- const Node *mask = in (1 );
1425
- if ( mask->Opcode () == Op_AndI &&
1426
- (t3 = phase->type (mask->in (2 ))->isa_int ()) &&
1427
- t3->is_con () ) {
1428
- Node *x = mask->in (1 );
1429
- jint maskbits = t3->get_con ();
1454
+ const Node* and_node = in (1 );
1455
+ if (and_node->Opcode () != Op_And (bt)) {
1456
+ return nullptr ;
1457
+ }
1458
+ const TypeInteger* mask_t = phase->type (and_node->in (2 ))->isa_integer (bt);
1459
+ if (mask_t != nullptr && mask_t ->is_con ()) {
1460
+ jlong maskbits = mask_t ->get_con_as_long (bt);
1430
1461
// Convert to "(x >> shift) & (mask >> shift)"
1431
- Node *shr_nomask = phase->transform ( new RShiftINode (mask->in (1 ), in (2 )) );
1432
- return new AndINode (shr_nomask, phase->intcon ( maskbits >> shift));
1462
+ Node* shr_nomask = phase->transform (RShiftNode::make (and_node->in (1 ), in (2 ), bt));
1463
+ return MulNode::make_and (shr_nomask, phase->integercon (maskbits >> shift, bt), bt);
1464
+ }
1465
+ return nullptr ;
1466
+ }
1467
+
1468
+ Node* RShiftINode::Ideal (PhaseGVN* phase, bool can_reshape) {
1469
+ Node* progress = IdealIL (phase, can_reshape, T_INT);
1470
+ if (progress == NodeSentinel) {
1471
+ return nullptr ;
1472
+ }
1473
+ if (progress != nullptr ) {
1474
+ return progress;
1433
1475
}
1476
+ int shift = maskShiftAmount (phase, this , BitsPerJavaInteger);
1477
+ assert (shift != 0 , " handled by IdealIL" );
1434
1478
1435
1479
// Check for "(short[i] <<16)>>16" which simply sign-extends
1436
1480
const Node *shl = in (1 );
1437
- if ( shl->Opcode () != Op_LShiftI ) return nullptr ;
1481
+ if (shl->Opcode () != Op_LShiftI) {
1482
+ return nullptr ;
1483
+ }
1438
1484
1439
- if ( shift == 16 &&
1440
- (t3 = phase->type (shl->in (2 ))->isa_int ()) &&
1441
- t3->is_con (16 ) ) {
1485
+ const TypeInt* left_shift_t = phase->type (shl->in (2 ))->isa_int ();
1486
+ if (left_shift_t == nullptr ) {
1487
+ return nullptr ;
1488
+ }
1489
+ if (shift == 16 && left_shift_t ->is_con (16 )) {
1442
1490
Node *ld = shl->in (1 );
1443
- if ( ld->Opcode () == Op_LoadS ) {
1491
+ if ( ld->Opcode () == Op_LoadS) {
1444
1492
// Sign extension is just useless here. Return a RShiftI of zero instead
1445
1493
// returning 'ld' directly. We cannot return an old Node directly as
1446
1494
// that is the job of 'Identity' calls and Identity calls only work on
@@ -1458,9 +1506,7 @@ Node *RShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
1458
1506
}
1459
1507
1460
1508
// Check for "(byte[i] <<24)>>24" which simply sign-extends
1461
- if ( shift == 24 &&
1462
- (t3 = phase->type (shl->in (2 ))->isa_int ()) &&
1463
- t3->is_con (24 ) ) {
1509
+ if (shift == 24 && left_shift_t ->is_con (24 )) {
1464
1510
Node *ld = shl->in (1 );
1465
1511
if (ld->Opcode () == Op_LoadB) {
1466
1512
// Sign extension is just useless here
@@ -1473,136 +1519,109 @@ Node *RShiftINode::Ideal(PhaseGVN *phase, bool can_reshape) {
1473
1519
return nullptr ;
1474
1520
}
1475
1521
1476
- // ------------------------------Value------------------------------------------
1477
- // A RShiftINode shifts its input2 right by input1 amount.
1478
- const Type* RShiftINode::Value (PhaseGVN* phase) const {
1479
- const Type *t1 = phase->type ( in (1 ) );
1480
- const Type *t2 = phase->type ( in (2 ) );
1522
+ const Type* RShiftNode::ValueIL (PhaseGVN* phase, BasicType bt) const {
1523
+ const Type* t1 = phase->type (in (1 ));
1524
+ const Type* t2 = phase->type (in (2 ));
1481
1525
// Either input is TOP ==> the result is TOP
1482
- if ( t1 == Type::TOP ) return Type::TOP;
1483
- if ( t2 == Type::TOP ) return Type::TOP;
1526
+ if (t1 == Type::TOP) {
1527
+ return Type::TOP;
1528
+ }
1529
+ if (t2 == Type::TOP) {
1530
+ return Type::TOP;
1531
+ }
1484
1532
1485
1533
// Left input is ZERO ==> the result is ZERO.
1486
- if ( t1 == TypeInt::ZERO ) return TypeInt::ZERO;
1534
+ if (t1 == TypeInteger::zero (bt)) {
1535
+ return TypeInteger::zero (bt);
1536
+ }
1487
1537
// Shift by zero does nothing
1488
- if ( t2 == TypeInt::ZERO ) return t1;
1538
+ if (t2 == TypeInt::ZERO) {
1539
+ return t1;
1540
+ }
1489
1541
1490
1542
// Either input is BOTTOM ==> the result is BOTTOM
1491
- if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
1492
- return TypeInt::INT;
1543
+ if (t1 == Type::BOTTOM || t2 == Type::BOTTOM) {
1544
+ return TypeInteger::bottom (bt);
1545
+ }
1493
1546
1494
- const TypeInt * r1 = t1->is_int (); // Handy access
1495
- const TypeInt * r2 = t2->is_int (); // Handy access
1547
+ const TypeInteger* r1 = t1->isa_integer (bt);
1548
+ const TypeInt* r2 = t2->isa_int ();
1496
1549
1497
1550
// If the shift is a constant, just shift the bounds of the type.
1498
- // For example, if the shift is 31, we just propagate sign bits.
1551
+ // For example, if the shift is 31/63 , we just propagate sign bits.
1499
1552
if (!r1->is_con () && r2->is_con ()) {
1500
1553
uint shift = r2->get_con ();
1501
- shift &= BitsPerJavaInteger-1 ; // semantics of Java shifts
1502
- // Shift by a multiple of 32 does nothing:
1503
- if (shift == 0 ) return t1;
1554
+ shift &= bits_per_java_integer (bt) - 1 ; // semantics of Java shifts
1555
+ // Shift by a multiple of 32/64 does nothing:
1556
+ if (shift == 0 ) {
1557
+ return t1;
1558
+ }
1504
1559
// Calculate reasonably aggressive bounds for the result.
1505
1560
// This is necessary if we are to correctly type things
1506
1561
// like (x<<24>>24) == ((byte)x).
1507
- jint lo = (jint) r1->_lo >> (jint)shift;
1508
- jint hi = (jint) r1->_hi >> (jint)shift;
1562
+ jlong lo = r1->lo_as_long () >> (jint)shift;
1563
+ jlong hi = r1->hi_as_long () >> (jint)shift;
1509
1564
assert (lo <= hi, " must have valid bounds" );
1510
- const TypeInt* ti = TypeInt::make (lo, hi, MAX2 (r1->_widen ,r2->_widen ));
1565
+ #ifdef ASSERT
1566
+ if (bt == T_INT) {
1567
+ jint lo_verify = checked_cast<jint>(r1->lo_as_long ()) >> (jint)shift;
1568
+ jint hi_verify = checked_cast<jint>(r1->hi_as_long ()) >> (jint)shift;
1569
+ assert ((checked_cast<jint>(lo) == lo_verify) && (checked_cast<jint>(hi) == hi_verify), " inconsistent" );
1570
+ }
1571
+ #endif
1572
+ const TypeInteger* ti = TypeInteger::make (lo, hi, MAX2 (r1->_widen ,r2->_widen ), bt);
1511
1573
#ifdef ASSERT
1512
1574
// Make sure we get the sign-capture idiom correct.
1513
- if (shift == BitsPerJavaInteger-1 ) {
1514
- if (r1->_lo >= 0 ) assert (ti == TypeInt::ZERO, " >>31 of + is 0" );
1515
- if (r1->_hi < 0 ) assert (ti == TypeInt::MINUS_1, " >>31 of - is -1" );
1575
+ if (shift == bits_per_java_integer (bt) - 1 ) {
1576
+ if (r1->lo_as_long () >= 0 ) {
1577
+ assert (ti == TypeInteger::zero (bt), " >>31/63 of + is 0" );
1578
+ }
1579
+ if (r1->hi_as_long () < 0 ) {
1580
+ assert (ti == TypeInteger::minus_1 (bt), " >>31/63 of - is -1" );
1581
+ }
1516
1582
}
1517
1583
#endif
1518
1584
return ti;
1519
1585
}
1520
1586
1521
1587
if (!r1->is_con () || !r2->is_con ()) {
1522
1588
// If the left input is non-negative the result must also be non-negative, regardless of what the right input is.
1523
- if (r1->_lo >= 0 ) {
1524
- return TypeInt ::make (0 , r1->_hi , MAX2 (r1->_widen , r2->_widen ));
1589
+ if (r1->lo_as_long () >= 0 ) {
1590
+ return TypeInteger ::make (0 , r1->hi_as_long () , MAX2 (r1->_widen , r2->_widen ), bt );
1525
1591
}
1526
1592
1527
1593
// Conversely, if the left input is negative then the result must be negative.
1528
- if (r1->_hi <= -1 ) {
1529
- return TypeInt ::make (r1->_lo , -1 , MAX2 (r1->_widen , r2->_widen ));
1594
+ if (r1->hi_as_long () <= -1 ) {
1595
+ return TypeInteger ::make (r1->lo_as_long () , -1 , MAX2 (r1->_widen , r2->_widen ), bt );
1530
1596
}
1531
1597
1532
- return TypeInt::INT ;
1598
+ return TypeInteger::bottom (bt) ;
1533
1599
}
1534
1600
1535
1601
// Signed shift right
1536
- return TypeInt::make (r1->get_con () >> (r2->get_con () & 31 ));
1602
+ return TypeInteger::make (r1->get_con_as_long (bt) >> (r2->get_con () & (bits_per_java_integer (bt) - 1 )), bt);
1603
+ }
1604
+
1605
+ const Type* RShiftINode::Value (PhaseGVN* phase) const {
1606
+ return ValueIL (phase, T_INT);
1537
1607
}
1538
1608
1539
1609
// =============================================================================
1540
1610
// ------------------------------Identity---------------------------------------
1541
1611
Node* RShiftLNode::Identity (PhaseGVN* phase) {
1542
- const TypeInt *ti = phase->type (in (2 ))->isa_int (); // Shift count is an int.
1543
- return (ti && ti->is_con () && (ti->get_con () & (BitsPerJavaLong - 1 )) == 0 ) ? in (1 ) : this ;
1612
+ return IdentityIL (phase, T_LONG);
1544
1613
}
1545
1614
1546
- // ------------------------------Value------------------------------------------
1547
- // A RShiftLNode shifts its input2 right by input1 amount.
1548
- const Type* RShiftLNode::Value (PhaseGVN* phase) const {
1549
- const Type *t1 = phase->type ( in (1 ) );
1550
- const Type *t2 = phase->type ( in (2 ) );
1551
- // Either input is TOP ==> the result is TOP
1552
- if ( t1 == Type::TOP ) return Type::TOP;
1553
- if ( t2 == Type::TOP ) return Type::TOP;
1554
-
1555
- // Left input is ZERO ==> the result is ZERO.
1556
- if ( t1 == TypeLong::ZERO ) return TypeLong::ZERO;
1557
- // Shift by zero does nothing
1558
- if ( t2 == TypeInt::ZERO ) return t1;
1559
-
1560
- // Either input is BOTTOM ==> the result is BOTTOM
1561
- if (t1 == Type::BOTTOM || t2 == Type::BOTTOM)
1562
- return TypeLong::LONG;
1563
-
1564
- const TypeLong *r1 = t1->is_long (); // Handy access
1565
- const TypeInt *r2 = t2->is_int (); // Handy access
1566
-
1567
- // If the shift is a constant, just shift the bounds of the type.
1568
- // For example, if the shift is 63, we just propagate sign bits.
1569
- if (!r1->is_con () && r2->is_con ()) {
1570
- uint shift = r2->get_con ();
1571
- shift &= (2 *BitsPerJavaInteger)-1 ; // semantics of Java shifts
1572
- // Shift by a multiple of 64 does nothing:
1573
- if (shift == 0 ) return t1;
1574
- // Calculate reasonably aggressive bounds for the result.
1575
- // This is necessary if we are to correctly type things
1576
- // like (x<<24>>24) == ((byte)x).
1577
- jlong lo = (jlong)r1->_lo >> (jlong)shift;
1578
- jlong hi = (jlong)r1->_hi >> (jlong)shift;
1579
- assert (lo <= hi, " must have valid bounds" );
1580
- const TypeLong* tl = TypeLong::make (lo, hi, MAX2 (r1->_widen ,r2->_widen ));
1581
- #ifdef ASSERT
1582
- // Make sure we get the sign-capture idiom correct.
1583
- if (shift == (2 *BitsPerJavaInteger)-1 ) {
1584
- if (r1->_lo >= 0 ) assert (tl == TypeLong::ZERO, " >>63 of + is 0" );
1585
- if (r1->_hi < 0 ) assert (tl == TypeLong::MINUS_1, " >>63 of - is -1" );
1586
- }
1587
- #endif
1588
- return tl;
1589
- }
1590
-
1591
- if (!r1->is_con () || !r2->is_con ()) {
1592
- // If the left input is non-negative the result must also be non-negative, regardless of what the right input is.
1593
- if (r1->_lo >= 0 ) {
1594
- return TypeLong::make (0 , r1->_hi , MAX2 (r1->_widen , r2->_widen ));
1595
- }
1596
-
1597
- // Conversely, if the left input is negative then the result must be negative.
1598
- if (r1->_hi <= -1 ) {
1599
- return TypeLong::make (r1->_lo , -1 , MAX2 (r1->_widen , r2->_widen ));
1600
- }
1601
-
1602
- return TypeLong::LONG;
1615
+ Node* RShiftLNode::Ideal (PhaseGVN *phase, bool can_reshape) {
1616
+ Node* progress = IdealIL (phase, can_reshape, T_LONG);
1617
+ if (progress == NodeSentinel) {
1618
+ return nullptr ;
1603
1619
}
1620
+ return progress;
1621
+ }
1604
1622
1605
- return TypeLong::make (r1->get_con () >> (r2->get_con () & 63 ));
1623
+ const Type* RShiftLNode::Value (PhaseGVN* phase) const {
1624
+ return ValueIL (phase, T_LONG);
1606
1625
}
1607
1626
1608
1627
// =============================================================================
0 commit comments