-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed
Closed
Copy link
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.C-bugCategory: This is a bug.Category: This is a bug.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
Consider this code: https://godbolt.org/z/QpiBK3 .
Code:
pub fn f(a: &mut i32, b: &mut i32) -> (i32, i32, i32) {
let c = *a;
let d = *b;
*a = 0;
(c, d, *b)
}Asm (1.30):
example::f:
movl (%rsi), %eax
movl (%rdx), %ecx
movl $0, (%rsi)
movl (%rdx), %edx
movl %eax, (%rdi)
movl %ecx, 4(%rdi)
movl %edx, 8(%rdi)
movq %rdi, %rax
retqWe read from memory at line let d = *b (from %rdx) and then we read from memory again at line (c, d, *b) (again from %rdx).
But in Rust (unlike C and C++) we know that two mutable references cannot point to same location. So, we missed optimization. This is regression
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.C-bugCategory: This is a bug.Category: This is a bug.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.