Skip to content

Commit 5944765

Browse files
committed
fix nits
1 parent 8414b3f commit 5944765

File tree

1 file changed

+6
-7
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+6
-7
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ use std::borrow::Cow;
106106
use crate::ssa::{AssignedValue, SsaLocals};
107107
use either::Either;
108108

109-
// LLVM optimizes the load of 16 byte as a single `mov`.
110-
// Bigger values make more `mov` instructions generated.
111-
// While changing code as this lint suggests, it becomes
112-
// a single load (`lea`) of an address in `.rodata`.
113-
const STACK_THRESHOLD: u64 = 16;
114-
115109
pub struct GVN;
116110

117111
impl<'tcx> MirPass<'tcx> for GVN {
@@ -373,6 +367,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
373367
#[instrument(level = "trace", skip(self), ret)]
374368
fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
375369
use Value::*;
370+
use abi::HasDataLayout;
371+
// LLVM optimizes the load of `sizeof(size_t) * 2` as a single `mov`,
372+
// which is cheap. Bigger values make more `mov` instructions generated.
373+
// After GVN, it becomes a single load (`lea`) of an address in `.rodata`.
374+
let stack_threshold = self.tcx.data_layout().pointer_size * 2;
376375
let vvalue = self.get(value);
377376
debug!(?vvalue);
378377
let op = match *vvalue {
@@ -417,7 +416,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
417416
let ptr_imm = Immediate::new_pointer_with_meta(data, meta, &self.ecx);
418417
ImmTy::from_immediate(ptr_imm, ty).into()
419418
} else if matches!(kind, AggregateTy::Array) {
420-
if ty.layout.size().bytes() <= STACK_THRESHOLD {
419+
if ty.layout.size() <= stack_threshold {
421420
return None;
422421
}
423422
let mut mplace = None;

0 commit comments

Comments
 (0)