Skip to content

Commit 74a4a77

Browse files
committed
Also early exit from Rvalue::Use
1 parent 1e1bc5f commit 74a4a77

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2626
) {
2727
match *rvalue {
2828
mir::Rvalue::Use(ref operand) => {
29+
if let mir::Operand::Constant(const_op) = operand {
30+
let val = self.eval_mir_constant(const_op);
31+
if val.all_bytes_uninit(self.cx.tcx()) {
32+
return;
33+
}
34+
}
35+
2936
let cg_operand = self.codegen_operand(bx, operand);
3037
// FIXME: consider not copying constants through stack. (Fixable by codegen'ing
3138
// constants into `OperandValue::Ref`; why don’t we do that yet if we don’t?)

tests/codegen/uninit-consts.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@ pub struct PartiallyUninit {
1111
y: MaybeUninit<[u8; 10]>,
1212
}
1313

14-
// CHECK: [[FULLY_UNINIT:@.*]] = private unnamed_addr constant [10 x i8] undef
15-
1614
// CHECK: [[PARTIALLY_UNINIT:@.*]] = private unnamed_addr constant <{ [4 x i8], [12 x i8] }> <{ [4 x i8] c"{{\\EF\\BE\\AD\\DE|\\DE\\AD\\BE\\EF}}", [12 x i8] undef }>, align 4
1715

1816
// This shouldn't contain undef, since it contains more chunks
1917
// than the default value of uninit_const_chunk_threshold.
2018
// CHECK: [[UNINIT_PADDING_HUGE:@.*]] = private unnamed_addr constant [32768 x i8] c"{{.+}}", align 4
2119

22-
// CHECK: [[FULLY_UNINIT_HUGE:@.*]] = private unnamed_addr constant [16384 x i8] undef
23-
2420
// CHECK-LABEL: @fully_uninit
2521
#[no_mangle]
2622
pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> {
2723
const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit();
28-
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 1 %_0, ptr align 1 {{.*}}[[FULLY_UNINIT]]{{.*}}, i{{(32|64)}} 10, i1 false)
24+
// CHECK-NEXT: start:
25+
// CHECK-NEXT: ret void
2926
M
3027
}
3128

@@ -49,6 +46,7 @@ pub const fn uninit_padding_huge() -> [(u32, u8); 4096] {
4946
#[no_mangle]
5047
pub const fn fully_uninit_huge() -> MaybeUninit<[u32; 4096]> {
5148
const F: MaybeUninit<[u32; 4096]> = MaybeUninit::uninit();
52-
// CHECK: call void @llvm.memcpy.{{.+}}(ptr align 4 %_0, ptr align 4 {{.*}}[[FULLY_UNINIT_HUGE]]{{.*}}, i{{(32|64)}} 16384, i1 false)
49+
// CHECK-NEXT: start:
50+
// CHECK-NEXT: ret void
5351
F
5452
}

0 commit comments

Comments
 (0)