Skip to content

Commit a6adf2d

Browse files
committed
Make cast_(un)signed and wrapping_add be rustc_early_inline (rather than always)
Obviously there's way more that could do this, but I don't to do *all* of them at once.
1 parent 5a244aa commit a6adf2d

7 files changed

+38
-40
lines changed

library/core/src/num/int_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ macro_rules! int_impl {
225225
#[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
226226
#[must_use = "this returns the result of the operation, \
227227
without modifying the original"]
228-
#[inline(always)]
228+
#[rustc_early_inline]
229229
pub const fn cast_unsigned(self) -> $UnsignedT {
230230
self as $UnsignedT
231231
}
@@ -1915,7 +1915,7 @@ macro_rules! int_impl {
19151915
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
19161916
#[must_use = "this returns the result of the operation, \
19171917
without modifying the original"]
1918-
#[inline(always)]
1918+
#[rustc_early_inline]
19191919
pub const fn wrapping_add(self, rhs: Self) -> Self {
19201920
intrinsics::wrapping_add(self, rhs)
19211921
}

library/core/src/num/uint_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ macro_rules! uint_impl {
277277
#[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
278278
#[must_use = "this returns the result of the operation, \
279279
without modifying the original"]
280-
#[inline(always)]
280+
#[rustc_early_inline]
281281
pub const fn cast_signed(self) -> $SignedT {
282282
self as $SignedT
283283
}
@@ -2070,7 +2070,7 @@ macro_rules! uint_impl {
20702070
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
20712071
#[must_use = "this returns the result of the operation, \
20722072
without modifying the original"]
2073-
#[inline(always)]
2073+
#[rustc_early_inline]
20742074
pub const fn wrapping_add(self, rhs: Self) -> Self {
20752075
intrinsics::wrapping_add(self, rhs)
20762076
}

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-abort.mir

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
88
let mut _8: u16;
99
scope 2 {
1010
}
11-
scope 3 (inlined <u16 as Step>::forward_checked) {
12-
scope 4 {
13-
scope 6 (inlined core::num::<impl u16>::checked_add) {
11+
scope 3 (inlined core::num::<impl u16>::wrapping_add) {
12+
}
13+
scope 4 (inlined <u16 as Step>::forward_checked) {
14+
scope 5 {
15+
scope 7 (inlined core::num::<impl u16>::checked_add) {
1416
let mut _5: (u16, bool);
1517
let mut _6: bool;
16-
scope 7 (inlined std::intrinsics::unlikely) {
18+
scope 8 (inlined std::intrinsics::unlikely) {
1719
let _7: ();
1820
}
1921
}
2022
}
21-
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
23+
scope 6 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
2224
let mut _3: bool;
2325
let mut _4: u16;
2426
}
2527
}
26-
scope 8 (inlined Option::<u16>::is_none) {
27-
scope 9 (inlined Option::<u16>::is_some) {
28-
scope 10 {
28+
scope 9 (inlined Option::<u16>::is_none) {
29+
scope 10 (inlined Option::<u16>::is_some) {
30+
scope 11 {
2931
}
3032
}
3133
}
32-
scope 11 (inlined core::num::<impl u16>::wrapping_add) {
33-
}
3434
}
3535

3636
bb0: {

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.panic-unwind.mir

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
88
let mut _8: u16;
99
scope 2 {
1010
}
11-
scope 3 (inlined <u16 as Step>::forward_checked) {
12-
scope 4 {
13-
scope 6 (inlined core::num::<impl u16>::checked_add) {
11+
scope 3 (inlined core::num::<impl u16>::wrapping_add) {
12+
}
13+
scope 4 (inlined <u16 as Step>::forward_checked) {
14+
scope 5 {
15+
scope 7 (inlined core::num::<impl u16>::checked_add) {
1416
let mut _5: (u16, bool);
1517
let mut _6: bool;
16-
scope 7 (inlined std::intrinsics::unlikely) {
18+
scope 8 (inlined std::intrinsics::unlikely) {
1719
let _7: ();
1820
}
1921
}
2022
}
21-
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
23+
scope 6 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u16>::try_from) {
2224
let mut _3: bool;
2325
let mut _4: u16;
2426
}
2527
}
26-
scope 8 (inlined Option::<u16>::is_none) {
27-
scope 9 (inlined Option::<u16>::is_some) {
28-
scope 10 {
28+
scope 9 (inlined Option::<u16>::is_none) {
29+
scope 10 (inlined Option::<u16>::is_some) {
30+
scope 11 {
2931
}
3032
}
3133
}
32-
scope 11 (inlined core::num::<impl u16>::wrapping_add) {
33-
}
3434
}
3535

3636
bb0: {

tests/mir-opt/pre-codegen/integer_methods_debug.cast_and_add.PreCodegen.after.panic-abort.mir

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ fn cast_and_add(_1: i32) -> u32 {
44
debug x => _1;
55
let mut _0: u32;
66
let mut _2: u32;
7-
8-
bb0: {
9-
_2 = core::num::<impl i32>::cast_unsigned(copy _1) -> [return: bb1, unwind unreachable];
7+
scope 1 (inlined core::num::<impl i32>::cast_unsigned) {
108
}
11-
12-
bb1: {
13-
_0 = core::num::<impl u32>::wrapping_add(move _2, const 42_u32) -> [return: bb2, unwind unreachable];
9+
scope 2 (inlined core::num::<impl u32>::wrapping_add) {
1410
}
1511

16-
bb2: {
12+
bb0: {
13+
_2 = copy _1 as u32 (IntToInt);
14+
_0 = Add(copy _2, const 42_u32);
1715
return;
1816
}
1917
}

tests/mir-opt/pre-codegen/integer_methods_debug.cast_and_add.PreCodegen.after.panic-unwind.mir

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ fn cast_and_add(_1: i32) -> u32 {
44
debug x => _1;
55
let mut _0: u32;
66
let mut _2: u32;
7-
8-
bb0: {
9-
_2 = core::num::<impl i32>::cast_unsigned(copy _1) -> [return: bb1, unwind continue];
7+
scope 1 (inlined core::num::<impl i32>::cast_unsigned) {
108
}
11-
12-
bb1: {
13-
_0 = core::num::<impl u32>::wrapping_add(move _2, const 42_u32) -> [return: bb2, unwind continue];
9+
scope 2 (inlined core::num::<impl u32>::wrapping_add) {
1410
}
1511

16-
bb2: {
12+
bb0: {
13+
_2 = copy _1 as u32 (IntToInt);
14+
_0 = Add(copy _2, const 42_u32);
1715
return;
1816
}
1917
}

tests/mir-opt/pre-codegen/integer_methods_debug.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
// EMIT_MIR integer_methods_debug.cast_and_add.PreCodegen.after.mir
77
pub fn cast_and_add(x: i32) -> u32 {
88
// CHECK-LABEL: fn cast_and_add(_1: i32) -> u32
9-
// CHECK: _2 = {{.+}}<impl i32>::cast_unsigned(copy _1)
10-
// CHECK: _0 = {{.+}}<impl u32>::wrapping_add(move _2, const 42_u32) ->
9+
// CHECK: (inlined {{.+}}<impl i32>::cast_unsigned)
10+
// CHECK: (inlined {{.+}}<impl u32>::wrapping_add)
11+
// CHECK: _2 = copy _1 as u32 (IntToInt);
12+
// CHECK: _0 = Add(copy _2, const 42_u32);
1113
x.cast_unsigned().wrapping_add(42)
1214
}

0 commit comments

Comments
 (0)