@@ -637,35 +637,44 @@ Node *AndLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
637
637
638
638
// =============================================================================
639
639
640
- static int getShiftCon (PhaseGVN * phase, Node * shiftNode, int retVal ) {
641
- const Type *t = phase->type (shiftNode->in (2 ));
642
- if (t == Type::TOP) return retVal; // Right input is dead.
643
- const TypeInt *t2 = t-> isa_int ();
644
- if (!t2 || !t2-> is_con ()) return retVal; // Right input is a constant.
645
-
646
- return t2-> get_con () ;
640
+ static bool const_shift_count (PhaseGVN* phase, Node* shiftNode, int * count ) {
641
+ const TypeInt* tcount = phase->type (shiftNode->in (2 ))-> isa_int ( );
642
+ if (tcount != NULL && tcount-> is_con ()) {
643
+ *count = tcount-> get_con ();
644
+ return true ;
645
+ }
646
+ return false ;
647
647
}
648
648
649
- static int maskShiftAmount (PhaseGVN *phase, Node *shiftNode, int nBits) {
650
- int shift = getShiftCon (phase, shiftNode, 0 );
651
- int maskedShift = shift & (nBits - 1 );
652
-
653
- if (maskedShift == 0 ) return 0 ; // Let Identity() handle 0 shift count.
649
+ static int maskShiftAmount (PhaseGVN* phase, Node* shiftNode, int nBits) {
650
+ int count = 0 ;
651
+ if (const_shift_count (phase, shiftNode, &count)) {
652
+ int maskedShift = count & (nBits - 1 );
653
+ if (maskedShift == 0 ) {
654
+ // Let Identity() handle 0 shift count.
655
+ return 0 ;
656
+ }
654
657
655
- if (shift != maskedShift) {
656
- shiftNode->set_req (2 , phase->intcon (maskedShift)); // Replace shift count with masked value.
657
- PhaseIterGVN* igvn = phase->is_IterGVN ();
658
- if (igvn) {
659
- igvn->rehash_node_delayed (shiftNode);
658
+ if (count != maskedShift) {
659
+ shiftNode->set_req (2 , phase->intcon (maskedShift)); // Replace shift count with masked value.
660
+ PhaseIterGVN* igvn = phase->is_IterGVN ();
661
+ if (igvn) {
662
+ igvn->rehash_node_delayed (shiftNode);
663
+ }
660
664
}
665
+ return maskedShift;
661
666
}
662
-
663
- return maskedShift;
667
+ return 0 ;
664
668
}
665
669
666
670
// ------------------------------Identity---------------------------------------
667
671
Node* LShiftINode::Identity (PhaseGVN* phase) {
668
- return ((getShiftCon (phase, this , -1 ) & (BitsPerJavaInteger - 1 )) == 0 ) ? in (1 ) : this ;
672
+ int count = 0 ;
673
+ if (const_shift_count (phase, this , &count) && (count & (BitsPerJavaInteger - 1 )) == 0 ) {
674
+ // Shift by a multiple of 32 does nothing
675
+ return in (1 );
676
+ }
677
+ return this ;
669
678
}
670
679
671
680
// ------------------------------Ideal------------------------------------------
@@ -773,7 +782,12 @@ const Type* LShiftINode::Value(PhaseGVN* phase) const {
773
782
// =============================================================================
774
783
// ------------------------------Identity---------------------------------------
775
784
Node* LShiftLNode::Identity (PhaseGVN* phase) {
776
- return ((getShiftCon (phase, this , -1 ) & (BitsPerJavaLong - 1 )) == 0 ) ? in (1 ) : this ;
785
+ int count = 0 ;
786
+ if (const_shift_count (phase, this , &count) && (count & (BitsPerJavaLong - 1 )) == 0 ) {
787
+ // Shift by a multiple of 64 does nothing
788
+ return in (1 );
789
+ }
790
+ return this ;
777
791
}
778
792
779
793
// ------------------------------Ideal------------------------------------------
@@ -878,26 +892,30 @@ const Type* LShiftLNode::Value(PhaseGVN* phase) const {
878
892
// =============================================================================
879
893
// ------------------------------Identity---------------------------------------
880
894
Node* RShiftINode::Identity (PhaseGVN* phase) {
881
- int shift = getShiftCon (phase, this , -1 );
882
- if (shift == -1 ) return this ;
883
- if ((shift & (BitsPerJavaInteger - 1 )) == 0 ) return in (1 );
884
-
885
- // Check for useless sign-masking
886
- if (in (1 )->Opcode () == Op_LShiftI &&
887
- in (1 )->req () == 3 &&
888
- in (1 )->in (2 ) == in (2 )) {
889
- shift &= BitsPerJavaInteger-1 ; // semantics of Java shifts
890
- // Compute masks for which this shifting doesn't change
891
- int lo = (-1 << (BitsPerJavaInteger - ((uint)shift)-1 )); // FFFF8000
892
- int hi = ~lo; // 00007FFF
893
- const TypeInt *t11 = phase->type (in (1 )->in (1 ))->isa_int ();
894
- if (!t11) return this ;
895
- // Does actual value fit inside of mask?
896
- if (lo <= t11->_lo && t11->_hi <= hi) {
897
- return in (1 )->in (1 ); // Then shifting is a nop
895
+ int count = 0 ;
896
+ if (const_shift_count (phase, this , &count)) {
897
+ if ((count & (BitsPerJavaInteger - 1 )) == 0 ) {
898
+ // Shift by a multiple of 32 does nothing
899
+ return in (1 );
900
+ }
901
+ // Check for useless sign-masking
902
+ if (in (1 )->Opcode () == Op_LShiftI &&
903
+ in (1 )->req () == 3 &&
904
+ in (1 )->in (2 ) == in (2 )) {
905
+ count &= BitsPerJavaInteger-1 ; // semantics of Java shifts
906
+ // Compute masks for which this shifting doesn't change
907
+ int lo = (-1 << (BitsPerJavaInteger - ((uint)count)-1 )); // FFFF8000
908
+ int hi = ~lo; // 00007FFF
909
+ const TypeInt* t11 = phase->type (in (1 )->in (1 ))->isa_int ();
910
+ if (t11 == NULL ) {
911
+ return this ;
912
+ }
913
+ // Does actual value fit inside of mask?
914
+ if (lo <= t11->_lo && t11->_hi <= hi) {
915
+ return in (1 )->in (1 ); // Then shifting is a nop
916
+ }
898
917
}
899
918
}
900
-
901
919
return this ;
902
920
}
903
921
@@ -1082,8 +1100,11 @@ const Type* RShiftLNode::Value(PhaseGVN* phase) const {
1082
1100
// =============================================================================
1083
1101
// ------------------------------Identity---------------------------------------
1084
1102
Node* URShiftINode::Identity (PhaseGVN* phase) {
1085
- int shift = getShiftCon (phase, this , -1 );
1086
- if ((shift & (BitsPerJavaInteger - 1 )) == 0 ) return in (1 );
1103
+ int count = 0 ;
1104
+ if (const_shift_count (phase, this , &count) && (count & (BitsPerJavaInteger - 1 )) == 0 ) {
1105
+ // Shift by a multiple of 32 does nothing
1106
+ return in (1 );
1107
+ }
1087
1108
1088
1109
// Check for "((x << LogBytesPerWord) + (wordSize-1)) >> LogBytesPerWord" which is just "x".
1089
1110
// Happens during new-array length computation.
@@ -1266,7 +1287,12 @@ const Type* URShiftINode::Value(PhaseGVN* phase) const {
1266
1287
// =============================================================================
1267
1288
// ------------------------------Identity---------------------------------------
1268
1289
Node* URShiftLNode::Identity (PhaseGVN* phase) {
1269
- return ((getShiftCon (phase, this , -1 ) & (BitsPerJavaLong - 1 )) == 0 ) ? in (1 ) : this ;
1290
+ int count = 0 ;
1291
+ if (const_shift_count (phase, this , &count) && (count & (BitsPerJavaLong - 1 )) == 0 ) {
1292
+ // Shift by a multiple of 64 does nothing
1293
+ return in (1 );
1294
+ }
1295
+ return this ;
1270
1296
}
1271
1297
1272
1298
// ------------------------------Ideal------------------------------------------
@@ -1444,6 +1470,21 @@ uint MulAddS2INode::hash() const {
1444
1470
1445
1471
// ------------------------------Rotate Operations ------------------------------
1446
1472
1473
+ Node* RotateLeftNode::Identity (PhaseGVN* phase) {
1474
+ const Type* t1 = phase->type (in (1 ));
1475
+ if (t1 == Type::TOP) {
1476
+ return this ;
1477
+ }
1478
+ int count = 0 ;
1479
+ assert (t1->isa_int () || t1->isa_long (), " Unexpected type" );
1480
+ int mask = (t1->isa_int () ? BitsPerJavaInteger : BitsPerJavaLong) - 1 ;
1481
+ if (const_shift_count (phase, this , &count) && (count & mask) == 0 ) {
1482
+ // Rotate by a multiple of 32/64 does nothing
1483
+ return in (1 );
1484
+ }
1485
+ return this ;
1486
+ }
1487
+
1447
1488
const Type* RotateLeftNode::Value (PhaseGVN* phase) const {
1448
1489
const Type* t1 = phase->type (in (1 ));
1449
1490
const Type* t2 = phase->type (in (2 ));
@@ -1460,11 +1501,10 @@ const Type* RotateLeftNode::Value(PhaseGVN* phase) const {
1460
1501
if (r1 == TypeInt::ZERO) {
1461
1502
return TypeInt::ZERO;
1462
1503
}
1463
- // Shift by zero does nothing
1504
+ // Rotate by zero does nothing
1464
1505
if (r2 == TypeInt::ZERO) {
1465
1506
return r1;
1466
1507
}
1467
-
1468
1508
if (r1->is_con () && r2->is_con ()) {
1469
1509
int shift = r2->get_con () & (BitsPerJavaInteger - 1 ); // semantics of Java shifts
1470
1510
return TypeInt::make ((r1->get_con () << shift) | (r1->get_con () >> (32 - shift)));
@@ -1479,11 +1519,10 @@ const Type* RotateLeftNode::Value(PhaseGVN* phase) const {
1479
1519
if (r1 == TypeLong::ZERO) {
1480
1520
return TypeLong::ZERO;
1481
1521
}
1482
- // Shift by zero does nothing
1522
+ // Rotate by zero does nothing
1483
1523
if (r2 == TypeInt::ZERO) {
1484
1524
return r1;
1485
1525
}
1486
-
1487
1526
if (r1->is_con () && r2->is_con ()) {
1488
1527
int shift = r2->get_con () & (BitsPerJavaLong - 1 ); // semantics of Java shifts
1489
1528
return TypeLong::make ((r1->get_con () << shift) | (r1->get_con () >> (64 - shift)));
@@ -1508,6 +1547,21 @@ Node* RotateLeftNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1508
1547
return NULL ;
1509
1548
}
1510
1549
1550
+ Node* RotateRightNode::Identity (PhaseGVN* phase) {
1551
+ const Type* t1 = phase->type (in (1 ));
1552
+ if (t1 == Type::TOP) {
1553
+ return this ;
1554
+ }
1555
+ int count = 0 ;
1556
+ assert (t1->isa_int () || t1->isa_long (), " Unexpected type" );
1557
+ int mask = (t1->isa_int () ? BitsPerJavaInteger : BitsPerJavaLong) - 1 ;
1558
+ if (const_shift_count (phase, this , &count) && (count & mask) == 0 ) {
1559
+ // Rotate by a multiple of 32/64 does nothing
1560
+ return in (1 );
1561
+ }
1562
+ return this ;
1563
+ }
1564
+
1511
1565
const Type* RotateRightNode::Value (PhaseGVN* phase) const {
1512
1566
const Type* t1 = phase->type (in (1 ));
1513
1567
const Type* t2 = phase->type (in (2 ));
@@ -1524,7 +1578,7 @@ const Type* RotateRightNode::Value(PhaseGVN* phase) const {
1524
1578
if (r1 == TypeInt::ZERO) {
1525
1579
return TypeInt::ZERO;
1526
1580
}
1527
- // Shift by zero does nothing
1581
+ // Rotate by zero does nothing
1528
1582
if (r2 == TypeInt::ZERO) {
1529
1583
return r1;
1530
1584
}
@@ -1533,7 +1587,6 @@ const Type* RotateRightNode::Value(PhaseGVN* phase) const {
1533
1587
return TypeInt::make ((r1->get_con () >> shift) | (r1->get_con () << (32 - shift)));
1534
1588
}
1535
1589
return TypeInt::INT;
1536
-
1537
1590
} else {
1538
1591
assert (t1->isa_long (), " Type must be a long" );
1539
1592
const TypeLong* r1 = t1->is_long ();
@@ -1542,7 +1595,7 @@ const Type* RotateRightNode::Value(PhaseGVN* phase) const {
1542
1595
if (r1 == TypeLong::ZERO) {
1543
1596
return TypeLong::ZERO;
1544
1597
}
1545
- // Shift by zero does nothing
1598
+ // Rotate by zero does nothing
1546
1599
if (r2 == TypeInt::ZERO) {
1547
1600
return r1;
1548
1601
}
0 commit comments