-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Open
Labels
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-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-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.
Description
Hi!
I am developing an application for an armv7 embedded device. I'm holding the application state in a stack-allocated enum, where one of the enum variations is 16k (total memory is 64k)
Switching to the huge app state, my microcontroller hard faults. I have played with a short repro on godbolt.org and I found that a particular pattern reserves stack space where I don't believe is necessary.
I tried this code:
pub fn init(a: usize) -> [usize; 1600] {
[a; 1600]
}
pub fn fun(bar: &mut [usize; 1600], w: bool, a: usize) {
*bar = init(a);
}I expected to see this happen:
generated machine code fills bar directly
Instead, this happened:
generated machine code fills stack then copies to bar
Code generated with -C opt-level=3 --target=armv7-unknown-linux-gnueabihf on godbolt.org
example::fun:
push {r7, lr}
sub.w sp, sp, #2000 ; I don't like this stack alloc
movs r1, #0
mov r3, sp
.LBB1_1:
str r2, [r3, r1]
adds r1, #4
cmp.w r1, #2000
bne .LBB1_1
mov r1, sp
mov.w r2, #2000
bl __aeabi_memcpy4
add.w sp, sp, #2000
pop {r7, pc}rustc --version --verbose:
1.43 and newer
Metadata
Metadata
Assignees
Labels
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-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-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.