Skip to content

Commit 73476d4

Browse files
committed
Auto merge of #122849 - clubby789:no-metadata, r=petrochenkov
Don't emit load metadata in debug mode r? `@ghost`
2 parents 8b9e47c + b500693 commit 73476d4

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::ty::layout::{
2020
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
2121
};
2222
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
23+
use rustc_session::config::OptLevel;
2324
use rustc_span::Span;
2425
use rustc_symbol_mangling::typeid::{
2526
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
@@ -551,6 +552,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
551552
layout: TyAndLayout<'tcx>,
552553
offset: Size,
553554
) {
555+
if bx.cx.sess().opts.optimize == OptLevel::No {
556+
// Don't emit metadata we're not going to use
557+
return;
558+
}
559+
554560
if !scalar.is_uninit_valid() {
555561
bx.noundef_metadata(load);
556562
}
@@ -667,6 +673,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
667673
return;
668674
}
669675

676+
if self.cx.sess().opts.optimize == OptLevel::No {
677+
// Don't emit metadata we're not going to use
678+
return;
679+
}
680+
670681
unsafe {
671682
let llty = self.cx.val_ty(load);
672683
let v = [

tests/codegen/intrinsics/typed_swap.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ pub unsafe fn swap_i32(x: &mut i32, y: &mut i32) {
2424
// CHECK-NOT: alloca
2525

2626
// CHECK: %[[TEMP:.+]] = load i32, ptr %x, align 4
27-
// CHECK-SAME: !noundef
27+
// OPT3-SAME: !noundef
2828
// OPT0: %[[TEMP2:.+]] = load i32, ptr %y, align 4
29-
// OPT0-SAME: !noundef
3029
// OPT0: store i32 %[[TEMP2]], ptr %x, align 4
3130
// OPT0-NOT: memcpy
3231
// OPT3-NOT: load
@@ -42,9 +41,9 @@ pub unsafe fn swap_pair(x: &mut (i32, u32), y: &mut (i32, u32)) {
4241
// CHECK-NOT: alloca
4342

4443
// CHECK: load i32
45-
// CHECK-SAME: !noundef
44+
// OPT3-SAME: !noundef
4645
// CHECK: load i32
47-
// CHECK-SAME: !noundef
46+
// OPT3-SAME: !noundef
4847
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %x, ptr align 4 %y, i64 8, i1 false)
4948
// CHECK: store i32
5049
// CHECK: store i32
@@ -57,10 +56,10 @@ pub unsafe fn swap_str<'a>(x: &mut &'a str, y: &mut &'a str) {
5756
// CHECK-NOT: alloca
5857

5958
// CHECK: load ptr
60-
// CHECK-SAME: !nonnull
61-
// CHECK-SAME: !noundef
59+
// OPT3-SAME: !nonnull
60+
// OPT3-SAME: !noundef
6261
// CHECK: load i64
63-
// CHECK-SAME: !noundef
62+
// OPT3-SAME: !noundef
6463
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %x, ptr align 8 %y, i64 16, i1 false)
6564
// CHECK: store ptr
6665
// CHECK: store i64

tests/codegen/loads.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
1+
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 -O
2+
23
#![crate_type = "lib"]
34
#![feature(generic_nonzero)]
45

tests/codegen/overaligned-constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// CHECK-LABEL: @_ZN20overaligned_constant4main
1717
// CHECK: [[full:%_.*]] = alloca %SmallStruct, align 8
1818
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[full]], ptr align 8 @0, i64 32, i1 false)
19-
// CHECK: %b.0 = load i32, ptr @0, align 4,
19+
// CHECK: %b.0 = load i32, ptr @0, align 4
2020
// CHECK: %b.1 = load i32, ptr getelementptr inbounds ({{.*}}), align 4
2121
let mut s = S(1);
2222

0 commit comments

Comments
 (0)