@@ -543,7 +543,8 @@ macro_rules! int_impl {
543
543
without modifying the original"]
544
544
#[ inline]
545
545
pub const fn checked_div( self , rhs: Self ) -> Option <Self > {
546
- if unlikely!( rhs == 0 || ( self == Self :: MIN && rhs == -1 ) ) {
546
+ // Using `&` helps LLVM see that it is the same check made in division.
547
+ if unlikely!( rhs == 0 || ( ( self == Self :: MIN ) & ( rhs == -1 ) ) ) {
547
548
None
548
549
} else {
549
550
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -569,7 +570,8 @@ macro_rules! int_impl {
569
570
without modifying the original"]
570
571
#[ inline]
571
572
pub const fn checked_div_euclid( self , rhs: Self ) -> Option <Self > {
572
- if unlikely!( rhs == 0 || ( self == Self :: MIN && rhs == -1 ) ) {
573
+ // Using `&` helps LLVM see that it is the same check made in division.
574
+ if unlikely!( rhs == 0 || ( ( self == Self :: MIN ) & ( rhs == -1 ) ) ) {
573
575
None
574
576
} else {
575
577
Some ( self . div_euclid( rhs) )
@@ -595,7 +597,8 @@ macro_rules! int_impl {
595
597
without modifying the original"]
596
598
#[ inline]
597
599
pub const fn checked_rem( self , rhs: Self ) -> Option <Self > {
598
- if unlikely!( rhs == 0 || ( self == Self :: MIN && rhs == -1 ) ) {
600
+ // Using `&` helps LLVM see that it is the same check made in division.
601
+ if unlikely!( rhs == 0 || ( ( self == Self :: MIN ) & ( rhs == -1 ) ) ) {
599
602
None
600
603
} else {
601
604
// SAFETY: div by zero and by INT_MIN have been checked above
@@ -621,7 +624,8 @@ macro_rules! int_impl {
621
624
without modifying the original"]
622
625
#[ inline]
623
626
pub const fn checked_rem_euclid( self , rhs: Self ) -> Option <Self > {
624
- if unlikely!( rhs == 0 || ( self == Self :: MIN && rhs == -1 ) ) {
627
+ // Using `&` helps LLVM see that it is the same check made in division.
628
+ if unlikely!( rhs == 0 || ( ( self == Self :: MIN ) & ( rhs == -1 ) ) ) {
625
629
None
626
630
} else {
627
631
Some ( self . rem_euclid( rhs) )
@@ -1466,7 +1470,8 @@ macro_rules! int_impl {
1466
1470
#[ must_use = "this returns the result of the operation, \
1467
1471
without modifying the original"]
1468
1472
pub const fn overflowing_div( self , rhs: Self ) -> ( Self , bool ) {
1469
- if unlikely!( self == Self :: MIN && rhs == -1 ) {
1473
+ // Using `&` helps LLVM see that it is the same check made in division.
1474
+ if unlikely!( ( self == Self :: MIN ) & ( rhs == -1 ) ) {
1470
1475
( self , true )
1471
1476
} else {
1472
1477
( self / rhs, false )
@@ -1496,7 +1501,8 @@ macro_rules! int_impl {
1496
1501
#[ must_use = "this returns the result of the operation, \
1497
1502
without modifying the original"]
1498
1503
pub const fn overflowing_div_euclid( self , rhs: Self ) -> ( Self , bool ) {
1499
- if unlikely!( self == Self :: MIN && rhs == -1 ) {
1504
+ // Using `&` helps LLVM see that it is the same check made in division.
1505
+ if unlikely!( ( self == Self :: MIN ) & ( rhs == -1 ) ) {
1500
1506
( self , true )
1501
1507
} else {
1502
1508
( self . div_euclid( rhs) , false )
@@ -1527,7 +1533,8 @@ macro_rules! int_impl {
1527
1533
#[ must_use = "this returns the result of the operation, \
1528
1534
without modifying the original"]
1529
1535
pub const fn overflowing_rem( self , rhs: Self ) -> ( Self , bool ) {
1530
- if unlikely!( self == Self :: MIN && rhs == -1 ) {
1536
+ // Using `&` helps LLVM see that it is the same check made in division.
1537
+ if unlikely!( ( self == Self :: MIN ) & ( rhs == -1 ) ) {
1531
1538
( 0 , true )
1532
1539
} else {
1533
1540
( self % rhs, false )
@@ -1558,7 +1565,8 @@ macro_rules! int_impl {
1558
1565
without modifying the original"]
1559
1566
#[ inline]
1560
1567
pub const fn overflowing_rem_euclid( self , rhs: Self ) -> ( Self , bool ) {
1561
- if unlikely!( self == Self :: MIN && rhs == -1 ) {
1568
+ // Using `&` helps LLVM see that it is the same check made in division.
1569
+ if unlikely!( ( self == Self :: MIN ) & ( rhs == -1 ) ) {
1562
1570
( 0 , true )
1563
1571
} else {
1564
1572
( self . rem_euclid( rhs) , false )
0 commit comments