-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Mark &mut pointers as noalias once LLVM no longer miscompiles them #31681
Comments
Was just reading about this, and it was a little hard to find the LLVM bug report, so for reference, here it is. |
I've been working through the LLVM optimization passes to find noalias-related bugs. Known issues:
Some of these are less important because they can't caused a wrong value, only a segfault. There are probably a few more lurking issues, but hopefully I've found most of them. (Edited by bluss 2016-12-15 to strike out fixed bug) |
@eefriedman LLVM bug 27859 is closed. |
…with_element Due to missing noalias annotations for &mut T in general (issue rust-lang#31681), in larger programs extend_from_slice and extend_with_element may both compile very poorly. What is observed is that the .set_len() calls are not lifted out of the loop, even for `Vec<u8>`. Use a local length variable for the Vec length instead, and use a scope guard to write this value back to self.len when the scope ends or on panic. Then the alias analysis is easy. This affects extend_from_slice, extend_with_element, the vec![x; n] macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not have triggered since inlining can be enough for the compiler to get it right).
…d, r=alexcrichton Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element Due to missing noalias annotations for &mut T in general (issue #31681), in larger programs extend_from_slice and extend_with_element may both compile very poorly. What is observed is that the .set_len() calls are not lifted out of the loop, even for `Vec<u8>`. Use a local length variable for the Vec length instead, and use a scope guard to write this value back to self.len when the scope ends or on panic. Then the alias analysis is easy. This affects extend_from_slice, extend_with_element, the vec![x; n] macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not have triggered since inlining can be enough for the compiler to get it right). Fixes #32155 Fixes #33518 Closes #17844
@eefriedman bug 25422 should be fixed. Any progress on bug 27860 ? (Edited by mbrubeck 2017-03-30 to link to new LLVM bugzilla domain) |
NewGVN was recently merged into LLVM (still experimental), it's a rewrite of the global value numbering algorithm. The last remaining bug on our list is bug in the old gvn implementation. I compiled the example codes in the bug report with the new gvn algorithm, and they work fine, so hopefully LLVM 5.0 will stabilize NewGVN and we can turn this optimization back on. |
I talked with Davide Italiano from LLVM and the goal is for NewGVN to be turned on in LLVM 6.0. #42047 is a reduced test case of a real performance problem that's helped by this that we're running into with WebRender so it would be nice to fix this sooner rather than later. |
I support enabling this if and only if Maybe if "treat function calls as possible branch point" is a function-level annotation in LLVM the only difference would be emitting/not emitting that. |
Is it possible for us to get a cargobomb run with the patch reverted to see if we trigger any bad codegen? |
Any best guesses when this improvement would be available in Rust nightly (with and without |
Is PR27860 actually a problem for Rust? I think every time we emit |
Maybe a |
@oyvindln if you want to turn on newgvn to compare things, RUSTFLAGS="-C llvm-args=-enable-newgvn" might work. |
It's unclear from reading this what the state of this bug is. Do we still believe that NewGVN will fix this issue? |
I think all "noalias-exclusive" bugs are fixed, so it might be worth giving it a try and opening a PR. |
Does that enablement need to be conditional on LLVM version? |
I think. 4.0 should be fine. |
Update: there's now a -Z flag for opting-in to this on an experimental basis: #45012. It also seems as though the behavior is enabled by default for panic=abort builds. However, I think this might be worth keeping open until we concretely determine whether or not we'll be able to turn this on for panic=unwind builds (see #45029 ). |
What's the state of this given that LLVM has been upgraded to 6.0? |
To help finding this issue: the -Z flag is |
Looks like the last part of the checklist above landed with https://reviews.llvm.org/D38619#937247 |
Should we make a PR to always enable Cc @rust-lang/wg-codegen |
This used to be disabled due to LLVM bugs in the handling of noalias information in conjunction with unwinding. However, according to rust-lang#31681 all known LLVM bugs have been fixed by LLVM 6.0, so it's probably time to reenable this optimization. Noalias annotations will not be emitted by default if either -C panic=abort (as previously) or LLVM >= 6.0 (new). -Z mutable-noalias=no is left as an escape-hatch to allow debugging problems suspected to stem from this change.
Emit noalias on &mut parameters by default This used to be disabled due to LLVM bugs in the handling of noalias information in conjunction with unwinding. However, according to #31681 all known LLVM bugs have been fixed by LLVM 6.0, so it's probably time to reenable this optimization. -Z no-mutable-noalias is left as an escape-hatch to debug problems suspected to stem from this change.
As #50744 has landed, this can be closed. |
🎉 |
This issue tracks the undoing of the workaround introduced in #31545 on account of a bug in LLVM. cc @dotdash
The text was updated successfully, but these errors were encountered: