Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 41484d3

Browse files
committed
disallow duplicate arrays in rvalue
1 parent 8093f11 commit 41484d3

File tree

1 file changed

+14
-10
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+14
-10
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
816816
}
817817
Operand::Copy(ref mut place) | Operand::Move(ref mut place) => {
818818
let value = self.simplify_place_value(place, location)?;
819-
// Ignore arrays in operand.
819+
// Ignore arrays in operands.
820820
if let Value::Aggregate(AggregateTy::Array, ..) = self.get(value) {
821821
return None;
822822
}
@@ -1492,14 +1492,6 @@ impl<'tcx> VnState<'_, 'tcx> {
14921492
if let Value::Constant { value, disambiguator: _ } = value
14931493
&& value.is_deterministic()
14941494
{
1495-
// Prevent code bloat that makes
1496-
// `_2 = _1` now resolved to `_2 = <evaluated array>`.
1497-
if let Const::Val(_, ty) = value
1498-
&& ty.is_array()
1499-
&& self.rev_locals[index].len() > 1
1500-
{
1501-
return None;
1502-
}
15031495
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: *value });
15041496
}
15051497

@@ -1566,7 +1558,19 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
15661558
let Some(value) = value else { return };
15671559

15681560
debug!(before_rvalue = ?rvalue);
1569-
if let Some(const_) = self.try_as_constant(value) {
1561+
// Ignore arrays in operands.
1562+
// Prevent code bloat that makes
1563+
// `_2 = _1` now resolved to `_2 = <evaluated array>`.
1564+
let disallow_dup_array = if rvalue.ty(self.local_decls, self.tcx).is_array()
1565+
&& let Some(locals) = self.rev_locals.get(value).as_deref()
1566+
&& let [first, ..] = locals[..]
1567+
{
1568+
first != lhs.local
1569+
} else {
1570+
false
1571+
};
1572+
1573+
if !disallow_dup_array && let Some(const_) = self.try_as_constant(value) {
15701574
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
15711575
} else if let Some(local) = self.try_as_local(value, location)
15721576
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))

0 commit comments

Comments
 (0)