-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worse codegen with mem::take(vec)
than on stable
#103840
Comments
Godbolt: https://rust.godbolt.org/z/4GTrh1EGx Result IR can be further optimized by GVN, so this might be addressable on the LLVM side. |
Looks like this got a bit worse on LLVM main because an additional assume is being preserved: https://llvm.godbolt.org/z/95eMe6j7q Anyway, there is a phase ordering problem here. MemCpyOpt runs after GVN, and only at that point do we convert the memcpy into a memset, which makes the following load from it easy to fold. An easy fix would probably be to support memset in InstCombine load store forwarding. But this is no longer going to fix this issue due to the aforementioned assume issue. Ugh. |
Upstream patch for InstCombine: https://reviews.llvm.org/D137323 An alternative solution would be to move MemCpyOpt prior to GVN, but I'm not sure whether that would cause other issues. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
Upstream patch for SimplifyCFG: https://reviews.llvm.org/D137339 Together these produce the following final IR:
Ignoring the opportunity to form a usub.sat, this is optimal. |
Nightly now compiles to example::foo:
mov rax, qword ptr [rdi + 16]
xor ecx, ecx
sub rax, 1
cmovae rcx, rax
mov qword ptr [rdi + 16], rcx
ret |
Needs codegen test. |
Would just |
Sounds reasonable. |
Add codegen test for issue 103840 Closes rust-lang#103840
I'm no longer having issues with the codegen test, LLVM 16 upgrade seems to have made it more reliable. |
With this code
Stable produces
Whereas beta/nightly produces
searched nightlies: from nightly-2022-07-02 to nightly-2022-07-03
regressed nightly: nightly-2022-07-03
searched commit range: 46b8c23...f2d9393
regressed commit: 0075bb4
bisected with cargo-bisect-rustc v0.6.4
Host triple: x86_64-unknown-linux-gnu
The text was updated successfully, but these errors were encountered: