-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Unnecessary copy when constructing arrays from returned arrays? #62446
Copy link
Copy link
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)Fixed by the Named Return Value Opt. (NRVO)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsArea: MIR optimizationsA-mir-opt-nrvoFixed by the Named Return Value Opt. (NRVO)Fixed by the Named Return Value Opt. (NRVO)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I want to construct a big array by concatenating smaller arrays returned by other functions. As a simple example:
Rust nightly generates a call to memcpy.
Is there a way to prevent this memcpy? Am I missing obvious other way to write this function?
Of course one could rewrite the called function
fto take a&mut [u64]instead of returning the array, but that removes compile-time checks on the length and introduces bounds checks. Using&mut [u64;40]as an "out" argument solves that problem, but then I don't see a safe way to get two&mut [u64;40]into[u64;80]without usingtransmute.(Background: I'm implementing the XMSSMT hash-based signature in Rust, which involves concatenating lots of hashes. The usual Rust hash library returns an array (actually a
GenericArray) instead of using a&mut [u64;...]parameter which led me to believe that the copy could be optimised away.)