Codegen regression with references
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I tried this code:
extern "Rust" {
fn fancy();
}
pub fn noalias(x: &mut u32) {
*x += 1;
unsafe { fancy() };
*x += 1;
}
pub unsafe fn can_alias(x: *mut u32) {
*x += 1;
unsafe { fancy() };
*x += 1;
}
https://godbolt.org/z/GKenzzsq9
I expected to see this happen: the fn noalias version is optimized better than the fn can_alias version.
Instead, this happened:
The 1.53 version of fn noalias compiled to the same as fn can_alias.
The diff from 1.53 -> 1.54 is as follows:
example::noalias:
+ push r14
push rbx
- mov rbx, rdi
- add dword ptr [rdi], 1
+ push rax
+ mov r14, rdi
+ mov ebx, dword ptr [rdi]
+ lea eax, [rbx + 1]
+ mov dword ptr [rdi], eax
call qword ptr [rip + fancy@GOTPCREL]
- add dword ptr [rbx], 1
+ add ebx, 2
+ mov dword ptr [r14], ebx
+ add rsp, 8
pop rbx
+ pop r14
ret
Version it worked on
1.53
It most recently worked on:
Version with regression
1.54, 1.28, 1.29
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust example in the issue and inspect its Godbolt output for Rust 1.53 versus the reported versions. Compare the generated code for noalias and can_alias, then trace the compiler codegen behavior responsible for the regression. Done means the mutable-reference version again receives the expected optimization distinction from the raw-pointer version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100