Open
Description
The following code results in a
being dereferenced again for the return value: (https://godbolt.org/z/YnrzMa3oj)
pub unsafe fn g(a: *mut i32, b: *mut i32) -> i32 {
*a = 0;
*b = 1;
return *a;
}
That is to be expected. In contrast, the same function with references avoids the load: (https://godbolt.org/z/YnrzMa3oj)
pub fn g_ref(a: &mut i32, b: &mut i32) -> i32 {
*a = 0;
*b = 1;
return *a;
}
However, if we change the code to the following: (https://godbolt.org/z/YnrzMa3oj)
pub fn g(a: *mut i32, b: *mut i32, x: *const i32) {
let a = &mut *a;
let b = &mut *b;
*a = 10;
*b = 11;
return *a;
}
then the extra dereference is not optimized out as it should be, because do not emit anything like noalias
inside functions.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationCategory: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to performance of generated code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Working group: LLVM backend code generation