Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upregression: dead heap allocations aren't optimized out anymore #24194
Comments
This comment has been minimized.
This comment has been minimized.
|
hmmm, I'm not so sure if it's a regression. It still works for vectors: http://is.gd/yNAFF6 . Maybe it never worked for boxes? |
steveklabnik
added
the
A-codegen
label
Apr 9, 2015
This comment has been minimized.
This comment has been minimized.
|
So, where do we go with this ticket? Was/is this a regression? is it worth tracking? |
This comment has been minimized.
This comment has been minimized.
|
@steveklabnik Probably a regression from when we moved from actual zeroing-drop to using the non-zero drop pattern. The check for that pattern basically says "leak this if the adress matches the drop pattern", so LLVM cannot remove the allocation because that would change semantics. Dynamic drop will fix this, and I think we should keep this open to track that, just to make sure. |
This comment has been minimized.
This comment has been minimized.
|
This appears to be fixed: https://is.gd/kT0Gs9 Is this worth creating some kind of regression test for? |
This comment has been minimized.
This comment has been minimized.
|
We could test it by adding a run pass test that uses a custom allocator (which doesn't allocate, but panics). |
bluss
added
the
E-needstest
label
Mar 4, 2017
This comment has been minimized.
This comment has been minimized.
|
tentatively needstest, then. Maybe a src/test/codegen test? |
nagisa
referenced this issue
May 22, 2017
Closed
Use simple io::Error for &[u8] Read and Write impl #42156
This comment has been minimized.
This comment has been minimized.
|
Seems to not work again on nightly. |
nagisa
added
regression-from-stable-to-nightly
T-compiler
and removed
E-needstest
labels
May 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I've used @Mark-Simulacrum 's bisection tool to find out the regressing commit. It was the LLVM 4.0 upgrade, commit 0777c75 . |
brson
added
I-slow
P-medium
A-LLVM
labels
Jun 1, 2017
nagisa
self-assigned this
Jun 1, 2017
This comment has been minimized.
This comment has been minimized.
|
Assigning myself just so it stays on my to-do list. Not immediately working on it, though. Feel free to take over if you want. |
This comment has been minimized.
This comment has been minimized.
|
Historically this optimization was done by rust-lang/llvm@4daef48 but this commit was not carried forward to our current branch when the 4.0 upgrade was done because it no longer applies cleanly (IIRC) |
This comment has been minimized.
This comment has been minimized.
|
Sadly, I couldn’t make the patch above to work. In fact, some testing seems to indicate that the responsibility for eliding allocations has been moved out of LLVM into clang. Namely, code like this
when compiled with
whereas if the special handling of the built-ins is not disabled (i.e. without This seems to suggest to me that, unless we do some serious patchwork on LLVM (pretty sure we don’t want to do that), it falls onto rustc to optimise out heap allocations now. This could also very well be a bug. I have a test case on hand that does optimise out on 3.9 but not on 4.0. I might do a bisection. |
This comment has been minimized.
This comment has been minimized.
|
Okay, never mind. I got it to work. |
nagisa
added a commit
to nagisa/rust
that referenced
this issue
Jun 3, 2017
nagisa
added a commit
to nagisa/rust
that referenced
this issue
Jun 3, 2017
wesleywiser
referenced this issue
Jun 9, 2017
Closed
Box::new() performance regression between 1.18 and 1.19 beta #42562
bors
added a commit
that referenced
this issue
Jun 10, 2017
bors
added a commit
that referenced
this issue
Jun 10, 2017
bors
added a commit
that referenced
this issue
Jun 14, 2017
This comment has been minimized.
This comment has been minimized.
|
The LLVM upgrade reintroduces optimisation for _rust_allocate, but the optimisation for __rust_allocate_zeroed was backed out due to weird UB-like behaviour with bitvec iterators in rustc_data_structures. Should investigate eventually. Assigning myself. |
This comment has been minimized.
This comment has been minimized.
|
cc @arielb1 you were interested in this yesterday. |
bors
closed this
in
8938269
Jun 16, 2017
nagisa
reopened this
Jun 16, 2017
Mark-Simulacrum
added
the
C-enhancement
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I believe this is no longer a regression, so untagging as a regression. |
alexcrichton
removed
the
regression-from-stable-to-nightly
label
Jul 23, 2017
This comment has been minimized.
This comment has been minimized.
|
It's not very clear to me whether this is still actionable. The original snippet doesn't seem to be misoptimised anymore. Can someone produce a new snippet that demonstrates the continued existence of the issue? Should the issue be closed? |
This comment has been minimized.
This comment has been minimized.
|
This should stay open as only a handful of alllocating functions are
currently handled (i.e. malloc equivalent but not realloc IIRC).
…On Mon, Apr 2, 2018, 14:37 Anthony Ramine ***@***.***> wrote:
It's not very clear to me whether this is still actionable. The original
snippet doesn't seem to be misoptimised anymore. Can someone produce a new
snippet that demonstrates the continued existence of the issue? Should the
issue be closed?
Cc @rust-lang/wg-codegen
<https://github.com/orgs/rust-lang/teams/wg-codegen>
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#24194 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApc0mikNK6SdwDWKu-Gccdw9qaNIrHUks5tkg2RgaJpZM4D8f_0>
.
|
This comment has been minimized.
This comment has been minimized.
|
Or was it calloc-equivalent.
…On Tue, Apr 3, 2018, 12:13 Simonas Kazlauskas ***@***.***> wrote:
This should stay open as only a handful of alllocating functions are
currently handled (i.e. malloc equivalent but not realloc IIRC).
On Mon, Apr 2, 2018, 14:37 Anthony Ramine ***@***.***>
wrote:
> It's not very clear to me whether this is still actionable. The original
> snippet doesn't seem to be misoptimised anymore. Can someone produce a new
> snippet that demonstrates the continued existence of the issue? Should the
> issue be closed?
>
> Cc @rust-lang/wg-codegen
> <https://github.com/orgs/rust-lang/teams/wg-codegen>
>
> —
> You are receiving this because you modified the open/close state.
> Reply to this email directly, view it on GitHub
> <#24194 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AApc0mikNK6SdwDWKu-Gccdw9qaNIrHUks5tkg2RgaJpZM4D8f_0>
> .
>
|
This comment has been minimized.
This comment has been minimized.
|
@nagisa Any snippet demonstrating the issue? |
This comment has been minimized.
This comment has been minimized.
#![feature(allocator_api)]
use std::heap::{Heap, Layout, Alloc};
pub unsafe fn alloc_zeroed_doesnt_optimise() {
let _ = Heap.alloc_zeroed(Layout::from_size_align_unchecked(4, 8));
}
extern "C" {
fn foo(x: *mut u8);
}
pub unsafe fn alloc_zeroed_should_optimise_rezeroing() {
let a = Heap.alloc_zeroed(Layout::from_size_align_unchecked(16, 8)).unwrap();
let slc = ::std::slice::from_raw_parts_mut(a, 16);
for i in slc.iter_mut() {
*i = 0;
}
foo(slc.as_mut_ptr());
} |
This comment has been minimized.
This comment has been minimized.
|
For searchability purposes, the functions are now called |
This comment has been minimized.
This comment has been minimized.
|
This was noticed in the wild on Stack Overflow. |
This comment has been minimized.
This comment has been minimized.
|
It would be nice if we didn't have to patch LLVM to support custom allocation functions. Unfortunately the last discussion on that topic didn't really end up anywhere: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093625.html |
This comment has been minimized.
This comment has been minimized.
|
The only way around that is to guarantee this optimization via MIR optimizations. But our MIR optimization story is nowhere near the level required for that. |
This comment has been minimized.
This comment has been minimized.
|
Couldn't this be generalized by having a "pure, no side-effects" unsafe attribute? |
oli-obk commentedApr 8, 2015
#22159 was closed after a llvm update (#22526). It used to work (I remember I tried it out). Now it doesn't work anymore.
http://is.gd/Wekr7w
LLVM-IR: