Skip to content

Commit

Permalink
Don't emit load metadata in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Mar 24, 2024
1 parent 4a52e9c commit a1308b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::Span;
use rustc_symbol_mangling::typeid::{
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
Expand Down Expand Up @@ -551,6 +552,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
layout: TyAndLayout<'tcx>,
offset: Size,
) {
if bx.cx.sess().opts.optimize == OptLevel::No {
// Don't emit metadata we're not going to use
return;
}

if !scalar.is_uninit_valid() {
bx.noundef_metadata(load);
}
Expand Down Expand Up @@ -667,6 +673,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
return;
}

if self.cx.sess().opts.optimize == OptLevel::No {
// Don't emit metadata we're not going to use
return;
}

unsafe {
let llty = self.cx.val_ty(load);
let v = [
Expand Down
3 changes: 2 additions & 1 deletion tests/codegen/loads.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 -O

#![crate_type = "lib"]
#![feature(generic_nonzero)]

Expand Down

0 comments on commit a1308b2

Please sign in to comment.