Description
Today, this code https://play.rust-lang.org/?version=nightly&mode=release&edition=2024&gist=09a5eaf64b3be527fef5a0589d6fe377
use std::cmp::Ordering;
pub fn foo(x: [i32; 1], y: [i32; 1]) -> Ordering {
Ord::cmp(&x[0], &y[0])
}
gives this optimized MIR:
fn foo(_1: [i32; 1], _2: [i32; 1]) -> std::cmp::Ordering {
debug x => _1;
debug y => _2;
let mut _0: std::cmp::Ordering;
let _3: &i32;
let _4: &i32;
scope 1 (inlined std::cmp::impls::<impl Ord for i32>::cmp) {
let mut _5: i32;
let mut _6: i32;
}
bb0: {
_3 = &_1[0 of 1];
_4 = &_2[0 of 1];
StorageLive(_5);
_5 = copy (*_3);
StorageLive(_6);
_6 = copy (*_4);
_0 = Cmp(move _5, move _6);
StorageDead(_6);
StorageDead(_5);
return;
}
}
It's a shame that we need to take a reference there in the MIR instead of just copying out of the place directly, like
bb0: {
StorageLive(_5);
_5 = copy _1[0 of 1];
StorageLive(_6);
_6 = copy _2[0 of 1];
_0 = Cmp(move _5, move _6);
StorageDead(_6);
StorageDead(_5);
return;
}
@cjgillot, is this something you think GVN could plausibly do?