From 744c664ba2e6440024457d5ec0d3600b3e0c0144 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 26 Nov 2023 00:36:56 -0800 Subject: [PATCH] Add a MIR pre-codegen test for derived PartialOrd --- tests/mir-opt/pre-codegen/derived_ord.rs | 9 + ....{impl#0}-partial_cmp.PreCodegen.after.mir | 159 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 tests/mir-opt/pre-codegen/derived_ord.rs create mode 100644 tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir diff --git a/tests/mir-opt/pre-codegen/derived_ord.rs b/tests/mir-opt/pre-codegen/derived_ord.rs new file mode 100644 index 0000000000000..bad751edf8419 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord.rs @@ -0,0 +1,9 @@ +// skip-filecheck +//@ compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=0 + +#![crate_type = "lib"] + +#[derive(PartialOrd, PartialEq)] +pub struct MultiField(char, i16); + +// EMIT_MIR derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir 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 new file mode 100644 index 0000000000000..dd7fce3ed0b46 --- /dev/null +++ b/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir @@ -0,0 +1,159 @@ +// MIR for `::partial_cmp` after PreCodegen + +fn ::partial_cmp(_1: &MultiField, _2: &MultiField) -> Option { + debug self => _1; + debug other => _2; + let mut _0: std::option::Option; + let mut _3: &char; + let mut _4: &char; + let mut _10: std::option::Option; + let mut _11: &i16; + let mut _12: &i16; + let _18: std::option::Option; + scope 1 { + debug cmp => _18; + } + scope 2 (inlined std::cmp::impls::::partial_cmp) { + debug self => _3; + debug other => _4; + let mut _9: std::cmp::Ordering; + scope 3 (inlined std::cmp::impls::::cmp) { + debug self => _3; + debug other => _4; + let mut _5: char; + let mut _6: char; + let mut _7: bool; + let mut _8: bool; + } + } + scope 4 (inlined std::cmp::impls::::partial_cmp) { + debug self => _11; + debug other => _12; + let mut _17: std::cmp::Ordering; + scope 5 (inlined std::cmp::impls::::cmp) { + debug self => _11; + debug other => _12; + let mut _13: i16; + let mut _14: i16; + let mut _15: bool; + let mut _16: bool; + } + } + + bb0: { + StorageLive(_3); + _3 = &((*_1).0: char); + StorageLive(_4); + _4 = &((*_2).0: char); + StorageLive(_9); + StorageLive(_5); + StorageLive(_6); + StorageLive(_7); + _5 = ((*_1).0: char); + _6 = ((*_2).0: char); + _7 = Lt(_5, _6); + switchInt(move _7) -> [0: bb1, otherwise: bb10]; + } + + bb1: { + StorageLive(_8); + _8 = Eq(_5, _6); + switchInt(move _8) -> [0: bb2, otherwise: bb3]; + } + + bb2: { + _9 = const Greater; + StorageDead(_8); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + _10 = Option::::Some(move _9); + StorageDead(_9); + StorageDead(_4); + StorageDead(_3); + goto -> bb11; + } + + bb3: { + StorageDead(_8); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_9); + StorageDead(_4); + StorageDead(_3); + StorageLive(_11); + _11 = &((*_1).1: i16); + StorageLive(_12); + _12 = &((*_2).1: i16); + StorageLive(_17); + StorageLive(_13); + StorageLive(_14); + StorageLive(_15); + _13 = ((*_1).1: i16); + _14 = ((*_2).1: i16); + _15 = Lt(_13, _14); + switchInt(move _15) -> [0: bb4, otherwise: bb8]; + } + + bb4: { + StorageLive(_16); + _16 = Eq(_13, _14); + switchInt(move _16) -> [0: bb5, otherwise: bb6]; + } + + bb5: { + _17 = const Greater; + goto -> bb7; + } + + bb6: { + _17 = const Equal; + goto -> bb7; + } + + bb7: { + StorageDead(_16); + goto -> bb9; + } + + bb8: { + _17 = const Less; + goto -> bb9; + } + + bb9: { + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); + _0 = Option::::Some(move _17); + StorageDead(_17); + StorageDead(_12); + StorageDead(_11); + goto -> bb12; + } + + bb10: { + _9 = const Less; + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + _10 = Option::::Some(move _9); + StorageDead(_9); + StorageDead(_4); + StorageDead(_3); + goto -> bb11; + } + + bb11: { + StorageLive(_18); + _18 = _10; + _0 = _10; + StorageDead(_18); + goto -> bb12; + } + + bb12: { + return; + } +}