Skip to content

Commit 8d5977d

Browse files
committed
Slightly simplify the iN::partial_cmp MIR
This saves some debug and scope metadata in every single function that calls it. Normally wouldn't be worth it, but with the derives there's *so* many of these.
1 parent 3da115a commit 8d5977d

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

library/core/src/cmp.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,14 @@ mod impls {
15481548
impl PartialOrd for $t {
15491549
#[inline]
15501550
fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
1551-
Some(self.cmp(other))
1551+
#[cfg(bootstrap)]
1552+
{
1553+
Some(self.cmp(other))
1554+
}
1555+
#[cfg(not(bootstrap))]
1556+
{
1557+
Some(crate::intrinsics::three_way_compare(*self, *other))
1558+
}
15521559
}
15531560
#[inline(always)]
15541561
fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
@@ -1566,12 +1573,12 @@ mod impls {
15661573
fn cmp(&self, other: &$t) -> Ordering {
15671574
#[cfg(bootstrap)]
15681575
{
1569-
// The order here is important to generate more optimal assembly.
1570-
// See <https://github.com/rust-lang/rust/issues/63758> for more info.
1571-
if *self < *other { Less }
1572-
else if *self == *other { Equal }
1573-
else { Greater }
1574-
}
1576+
// The order here is important to generate more optimal assembly.
1577+
// See <https://github.com/rust-lang/rust/issues/63758> for more info.
1578+
if *self < *other { Less }
1579+
else if *self == *other { Equal }
1580+
else { Greater }
1581+
}
15751582
#[cfg(not(bootstrap))]
15761583
{
15771584
crate::intrinsics::three_way_compare(*self, *other)

tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir

+5-13
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,16 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
1616
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
1717
debug self => _3;
1818
debug other => _4;
19+
let mut _5: char;
20+
let mut _6: char;
1921
let mut _7: std::cmp::Ordering;
20-
scope 3 (inlined std::cmp::impls::<impl Ord for char>::cmp) {
21-
debug self => _3;
22-
debug other => _4;
23-
let mut _5: char;
24-
let mut _6: char;
25-
}
2622
}
27-
scope 4 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
23+
scope 3 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
2824
debug self => _10;
2925
debug other => _11;
26+
let mut _12: i16;
27+
let mut _13: i16;
3028
let mut _14: std::cmp::Ordering;
31-
scope 5 (inlined std::cmp::impls::<impl Ord for i16>::cmp) {
32-
debug self => _10;
33-
debug other => _11;
34-
let mut _12: i16;
35-
let mut _13: i16;
36-
}
3729
}
3830

3931
bb0: {

0 commit comments

Comments
 (0)