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

Commit 817f097

Browse files
committed
really ignore nested arrays
1 parent 1000496 commit 817f097

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
927927
}
928928

929929
let (mut ty, variant_index) = match *kind {
930-
AggregateKind::Array(..) => {
930+
AggregateKind::Array(ty) => {
931931
assert!(!field_ops.is_empty());
932+
// Ignore nested arrays
933+
if ty.is_array() {
934+
return None;
935+
}
932936
(AggregateTy::Array, FIRST_VARIANT)
933937
}
934938
AggregateKind::Tuple => {
@@ -1501,17 +1505,12 @@ impl<'tcx> VnState<'_, 'tcx> {
15011505

15021506
let op = self.evaluated[index].as_ref()?;
15031507

1508+
// Ignore promoted arrays.
15041509
if let Either::Left(mplace) = op.as_mplace_or_imm()
1505-
&& let ty::Array(ty, _const) = mplace.layout.ty.kind()
1510+
&& mplace.layout.ty.is_array()
1511+
&& let Value::Projection(_index, ProjectionElem::Deref) = value
15061512
{
1507-
// ignore nested arrays
1508-
if ty.is_array() {
1509-
return None;
1510-
}
1511-
// ignore promoted arrays
1512-
else if let Value::Projection(_index, ProjectionElem::Deref) = value {
1513-
return None;
1514-
}
1513+
return None;
15151514
}
15161515

15171516
let value = op_to_prop_const(&mut self.ecx, op)?;

tests/mir-opt/const_array_locals.main.GVN.diff

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@
4949
+ _4 = const [255_i32, 105_i32, 15_i32, 39_i32, 62_i32, 251_i32, 191_i32, 178_i32, 9_i32, 4_i32, 56_i32, 221_i32];
5050
StorageLive(_5);
5151
- _5 = [const 193_i32, const 164_i32, const 194_i32, const 197_i32, const 6_i32, const 243_i32, const 218_i32, const 171_i32, const 87_i32, const 247_i32, const 104_i32, const 42_i32];
52-
- _3 = [move _4, move _5];
5352
+ _5 = const [193_i32, 164_i32, 194_i32, 197_i32, 6_i32, 243_i32, 218_i32, 171_i32, 87_i32, 247_i32, 104_i32, 42_i32];
54-
+ _3 = [const [255_i32, 105_i32, 15_i32, 39_i32, 62_i32, 251_i32, 191_i32, 178_i32, 9_i32, 4_i32, 56_i32, 221_i32], const [193_i32, 164_i32, 194_i32, 197_i32, 6_i32, 243_i32, 218_i32, 171_i32, 87_i32, 247_i32, 104_i32, 42_i32]];
53+
_3 = [move _4, move _5];
5554
StorageDead(_5);
5655
StorageDead(_4);
5756
StorageLive(_6);

0 commit comments

Comments
 (0)