Closed
Description
In the following code f
and g
have these lines swapped:
let item = SpecificDisplayItem::PopStackingContext;
clip.unwrap();
Unwrapping later causes f
to have an additional memcpy.
#[inline(never)]
pub fn f(clip: Option<&bool>) {
let item = SpecificDisplayItem::PopStackingContext;
clip.unwrap();
do_item(&DI {
item,
});
}
#[inline(never)]
pub fn g(clip: Option<&bool>) {
clip.unwrap();
let item = SpecificDisplayItem::PopStackingContext;
do_item(&DI {
item,
});
}
pub enum SpecificDisplayItem {
PopStackingContext,
Other([f64; 22]),
}
struct DI {
item: SpecificDisplayItem,
}
fn do_item(di: &DI) { unsafe { ext(di) } }
extern {
fn ext(di: &DI);
}
Compiles to:
example::f:
sub rsp, 360
test rdi, rdi
je .LBB0_1
mov qword ptr [rsp], 0
lea rdi, [rsp + 8]
lea rsi, [rsp + 184]
mov edx, 176
call memcpy@PLT
mov rdi, rsp
call ext@PLT
add rsp, 360
ret
.LBB0_1:
lea rdi, [rip + .Lbyte_str.2]
call core::panicking::panic@PLT
ud2
example::g:
sub rsp, 184
test rdi, rdi
je .LBB1_1
mov qword ptr [rsp], 0
mov rdi, rsp
call ext@PLT
add rsp, 184
ret
.LBB1_1:
lea rdi, [rip + .Lbyte_str.2]
call core::panicking::panic@PLT
ud2
Ideally, f
and g
should compile to the same thing.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: MIR optimizationsFixed by the Named Return Value Opt. (NRVO)Category: An issue proposing an enhancement or a PR with one.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.