Skip to content

Bad codegen for cloning a boxed array #41160

Closed
@arthurprs

Description

@arthurprs

For this code https://is.gd/JbfHAI

#![crate_type = "lib"]
pub extern fn clone(bits: &mut Box<[u64; 1024]>) -> Box<[u64; 1024]> {
  Box::new(**bits)
}

It copies data to the stack first, before allocating and copying again to the heap.

.cfi_offset rbx, -16
	mov	rsi, qword ptr [rdi]
	lea	rdi, [rsp]
	mov	edx, 8192
	call	memcpy@PLT
	mov	edi, 8192
	mov	esi, 8
	call	__rust_allocate@PLT
	mov	rbx, rax
	test	rbx, rbx
	je	.LBB0_2
	lea	rsi, [rsp]
	mov	edx, 8192
	mov	rdi, rbx
	call	memcpy@PLT
	mov	rax, rbx
	add	rsp, 8192
	pop	rbx
	ret

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions