Skip to content

Commit 503bdf8

Browse files
committed
Do not intern GVN temps.
1 parent 082e23d commit 503bdf8

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
//! _c = *_b // replaced by _c = _a
5454
//! ```
5555
56+
use rustc_const_eval::interpret::MemoryKind;
5657
use rustc_const_eval::interpret::{ImmTy, InterpCx, MemPlaceMeta, OpTy, Projectable, Scalar};
5758
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
5859
use rustc_data_structures::graph::dominators::Dominators;
@@ -316,24 +317,19 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
316317
if ty.is_zst() {
317318
ImmTy::uninit(ty).into()
318319
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
319-
let alloc_id = self
320-
.ecx
321-
.intern_with_temp_alloc(ty, |ecx, dest| {
322-
let variant_dest = if let Some(variant) = variant {
323-
ecx.project_downcast(dest, variant)?
324-
} else {
325-
dest.clone()
326-
};
327-
for (field_index, op) in fields.into_iter().enumerate() {
328-
let field_dest = ecx.project_field(&variant_dest, field_index)?;
329-
ecx.copy_op(op, &field_dest, /*allow_transmute*/ false)?;
330-
}
331-
ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), dest)
332-
})
333-
.ok()?;
334-
let mplace =
335-
self.ecx.raw_const_to_mplace(ConstAlloc { alloc_id, ty: ty.ty }).ok()?;
336-
mplace.into()
320+
let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?;
321+
let variant_dest = if let Some(variant) = variant {
322+
self.ecx.project_downcast(&dest, variant).ok()?
323+
} else {
324+
dest.clone()
325+
};
326+
for (field_index, op) in fields.into_iter().enumerate() {
327+
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
328+
self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?;
329+
}
330+
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
331+
self.ecx.alloc_mark_immutable(dest.ptr().provenance.unwrap()).ok()?;
332+
dest.into()
337333
} else {
338334
return None;
339335
}
@@ -839,10 +835,8 @@ fn op_to_prop_const<'tcx>(
839835
{
840836
let pointer = mplace.ptr().into_pointer_or_addr().ok()?;
841837
let (alloc_id, offset) = pointer.into_parts();
842-
return if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) {
843-
Some(ConstValue::Indirect { alloc_id, offset })
844-
} else {
845-
None
838+
if matches!(ecx.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_))) {
839+
return Some(ConstValue::Indirect { alloc_id, offset })
846840
}
847841
}
848842

tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
}
9090
}
9191

92-
alloc11 (size: 4, align: 2) {
92+
alloc12 (size: 4, align: 2) {
9393
01 00 63 00 │ ..c.
9494
}
9595

0 commit comments

Comments
 (0)