about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-03-24 10:01:37 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-03-24 10:01:37 -0700
commit8d5977d6af03af18c7851025b9ca70d0f2d12c86 (patch)
treef42e08238599f7b3db74c61ca30c8b0c45c7d5b0
parent3da115a93b782796e3d267266b4241e5258f1fef (diff)
downloadrust-8d5977d6af03af18c7851025b9ca70d0f2d12c86.tar.gz
rust-8d5977d6af03af18c7851025b9ca70d0f2d12c86.zip
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.
-rw-r--r--library/core/src/cmp.rs21
-rw-r--r--tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir18
2 files changed, 19 insertions, 20 deletions
diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs
index 7581c6dd759..e3b7cf84920 100644
--- a/library/core/src/cmp.rs
+++ b/library/core/src/cmp.rs
@@ -1548,7 +1548,14 @@ mod impls {
             impl PartialOrd for $t {
                 #[inline]
                 fn partial_cmp(&self, other: &$t) -> Option<Ordering> {
-                    Some(self.cmp(other))
+                    #[cfg(bootstrap)]
+                    {
+                        Some(self.cmp(other))
+                    }
+                    #[cfg(not(bootstrap))]
+                    {
+                        Some(crate::intrinsics::three_way_compare(*self, *other))
+                    }
                 }
                 #[inline(always)]
                 fn lt(&self, other: &$t) -> bool { (*self) < (*other) }
@@ -1566,12 +1573,12 @@ mod impls {
                 fn cmp(&self, other: &$t) -> Ordering {
                     #[cfg(bootstrap)]
                     {
-                    // The order here is important to generate more optimal assembly.
-                    // See <https://github.com/rust-lang/rust/issues/63758> for more info.
-                    if *self < *other { Less }
-                    else if *self == *other { Equal }
-                    else { Greater }
-                }
+                        // The order here is important to generate more optimal assembly.
+                        // See <https://github.com/rust-lang/rust/issues/63758> for more info.
+                        if *self < *other { Less }
+                        else if *self == *other { Equal }
+                        else { Greater }
+                    }
                     #[cfg(not(bootstrap))]
                     {
                         crate::intrinsics::three_way_compare(*self, *other)
diff --git a/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir
index 7ce2d229d54..a6c64425912 100644
--- a/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir
+++ b/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir
@@ -16,24 +16,16 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
     scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
         debug self => _3;
         debug other => _4;
+        let mut _5: char;
+        let mut _6: char;
         let mut _7: std::cmp::Ordering;
-        scope 3 (inlined std::cmp::impls::<impl Ord for char>::cmp) {
-            debug self => _3;
-            debug other => _4;
-            let mut _5: char;
-            let mut _6: char;
-        }
     }
-    scope 4 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
+    scope 3 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
         debug self => _10;
         debug other => _11;
+        let mut _12: i16;
+        let mut _13: i16;
         let mut _14: std::cmp::Ordering;
-        scope 5 (inlined std::cmp::impls::<impl Ord for i16>::cmp) {
-            debug self => _10;
-            debug other => _11;
-            let mut _12: i16;
-            let mut _13: i16;
-        }
     }
 
     bb0: {