-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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-codegenArea: Code generationArea: Code generationC-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
Given the following code where source will be excluded
pub fn store(source: &i32, dest: &mut i32) -> i32 {
let mut accum = 0;
for _ in 0..*source { // source will be excluded
accum += *dest;
}
accum
}The assembly output is:
example::store:
mov ecx, dword ptr [rdi]
mov edx, dword ptr [rsi]
imul edx, ecx
xor eax, eax
test ecx, ecx
cmovg eax, edx
ret
if source will be included the assembly code will increase more than
pub fn store(source: &i32, dest: &mut i32) -> i32 {
let mut accum = 0;
for _ in 0..=*source { // source will be included
accum += *dest;
}
accum
}The assembly output is:
example::store:
mov ecx, dword ptr [rdi]
test ecx, ecx
js .LBB0_1
mov r8d, dword ptr [rsi]
xor eax, eax
xor esi, esi
.LBB0_3:
xor edi, edi
cmp esi, ecx
setl dl
add eax, r8d
cmp esi, ecx
jge .LBB0_5
mov dil, dl
add esi, edi
cmp esi, ecx
jle .LBB0_3
.LBB0_5:
ret
.LBB0_1:
xor eax, eax
ret
I tested on rustc 1.64.0 with -C opt-level=3
nazar-pc
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-codegenArea: Code generationArea: Code generationC-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.