mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Auto merge of #142531 - ohadravid:better-storage-calls-copy-prop, r=tmiasko,cjgillot,saethlin
Remove fewer Storage calls in CopyProp and GVN
Modify the CopyProp and GVN MIR optimization passes to remove fewer `Storage{Live,Dead}` calls, allowing for better optimizations by LLVM - see rust-lang/rust#141649.
### Details
The idea is to use a new `MaybeUninitializedLocals` analysis and remove only the storage calls of locals that are maybe-uninit when accessed in a new location.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//@ compile-flags: -Copt-level=3
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Non-overlapping scopes should produce correct llvm.lifetimes,
|
||||
// which allow reuse of the same stack allocation.
|
||||
|
||||
pub struct WithOffset<T> {
|
||||
pub data: T,
|
||||
pub offset: usize,
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn peak_w(w: &WithOffset<&[u8; 16]>) {
|
||||
std::hint::black_box(w);
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn use_w(w: WithOffset<&[u8; 16]>) {
|
||||
std::hint::black_box(w);
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @scoped_small_structs
|
||||
// CHECK-NEXT: start:
|
||||
// CHECK-NEXT: [[B:%.*]] = alloca
|
||||
// CHECK-NEXT: [[A:%.*]] = alloca
|
||||
// CHECK: call void @llvm.lifetime.start.p0({{(i64 16, )?}}ptr {{.*}}[[A]])
|
||||
// CHECK: call void @llvm.lifetime.end.p0({{(i64 16, )?}}ptr {{.*}}[[A]])
|
||||
// CHECK: call void @llvm.lifetime.start.p0({{(i64 16, )?}}ptr {{.*}}[[B]])
|
||||
// CHECK: call void @llvm.lifetime.end.p0({{(i64 16, )?}}ptr {{.*}}[[B]])
|
||||
#[no_mangle]
|
||||
pub fn scoped_small_structs(buf: [u8; 16]) {
|
||||
{
|
||||
let w = WithOffset { data: &buf, offset: 0 };
|
||||
|
||||
peak_w(&w);
|
||||
use_w(w);
|
||||
}
|
||||
{
|
||||
let w2 = WithOffset { data: &buf, offset: 1 };
|
||||
|
||||
peak_w(&w2);
|
||||
use_w(w2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user