Skip to content

Commit 3bdb4a3

Browse files
committed
Do not intern GVN temps.
1 parent e2d0df4 commit 3bdb4a3

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;
@@ -323,24 +324,19 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
323324
if ty.is_zst() {
324325
ImmTy::uninit(ty).into()
325326
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
326-
let alloc_id = self
327-
.ecx
328-
.intern_with_temp_alloc(ty, |ecx, dest| {
329-
let variant_dest = if let Some(variant) = variant {
330-
ecx.project_downcast(dest, variant)?
331-
} else {
332-
dest.clone()
333-
};
334-
for (field_index, op) in fields.into_iter().enumerate() {
335-
let field_dest = ecx.project_field(&variant_dest, field_index)?;
336-
ecx.copy_op(op, &field_dest, /*allow_transmute*/ false)?;
337-
}
338-
ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), dest)
339-
})
340-
.ok()?;
341-
let mplace =
342-
self.ecx.raw_const_to_mplace(ConstAlloc { alloc_id, ty: ty.ty }).ok()?;
343-
mplace.into()
327+
let dest = self.ecx.allocate(ty, MemoryKind::Stack).ok()?;
328+
let variant_dest = if let Some(variant) = variant {
329+
self.ecx.project_downcast(&dest, variant).ok()?
330+
} else {
331+
dest.clone()
332+
};
333+
for (field_index, op) in fields.into_iter().enumerate() {
334+
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
335+
self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?;
336+
}
337+
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
338+
self.ecx.alloc_mark_immutable(dest.ptr().provenance.unwrap()).ok()?;
339+
dest.into()
344340
} else {
345341
return None;
346342
}
@@ -846,10 +842,8 @@ fn op_to_prop_const<'tcx>(
846842
{
847843
let pointer = mplace.ptr().into_pointer_or_addr().ok()?;
848844
let (alloc_id, offset) = pointer.into_parts();
849-
return if matches!(ecx.tcx.global_alloc(alloc_id), GlobalAlloc::Memory(_)) {
850-
Some(ConstValue::Indirect { alloc_id, offset })
851-
} else {
852-
None
845+
if matches!(ecx.tcx.try_get_global_alloc(alloc_id), Some(GlobalAlloc::Memory(_))) {
846+
return Some(ConstValue::Indirect { alloc_id, offset })
853847
}
854848
}
855849

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)