Skip to content

Commit 8e1dedb

Browse files
committed
rewrite ignore nested array condition
1 parent fa65e0f commit 8e1dedb

File tree

1 file changed

+17
-26
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+17
-26
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,38 +1466,29 @@ impl<'tcx> VnState<'_, 'tcx> {
14661466
// This was already constant in MIR, do not change it.
14671467
let value = self.get(index);
14681468
debug!(?index, ?value);
1469-
match value {
1470-
// If the constant is not deterministic, adding an additional mention of it in MIR will
1471-
// not give the same value as the former mention.
1472-
Value::Constant { value, disambiguator: _ } if value.is_deterministic() => {
1473-
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: *value });
1474-
}
1469+
// If the constant is not deterministic, adding an additional mention of it in MIR will
1470+
// not give the same value as the former mention.
1471+
if let Value::Constant { value, disambiguator: _ } = value
1472+
&& value.is_deterministic()
1473+
{
1474+
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: *value });
1475+
}
1476+
1477+
let op = self.evaluated[index].as_ref()?;
1478+
1479+
if let Either::Left(mplace) = op.as_mplace_or_imm()
1480+
&& let ty::Array(ty, _const) = mplace.layout.ty.kind()
1481+
{
14751482
// ignore nested arrays
1476-
Value::Aggregate(AggregateTy::Array, _, fields) => {
1477-
for f in fields {
1478-
if let Value::Constant { value: Const::Val(const_, _), .. } = self.get(*f)
1479-
&& let ConstValue::Indirect { .. } = const_
1480-
{
1481-
return None;
1482-
}
1483-
}
1483+
if ty.is_array() {
1484+
return None;
14841485
}
14851486
// ignore promoted arrays
1486-
Value::Projection(index, ProjectionElem::Deref) => {
1487-
if let Value::Constant { value: Const::Val(const_, ty), .. } = self.get(*index)
1488-
&& let ConstValue::Scalar(Scalar::Ptr(..)) = const_
1489-
&& let ty::Ref(region, ty, _mutability) = ty.kind()
1490-
&& region.is_erased()
1491-
&& ty.is_array()
1492-
{
1493-
return None;
1494-
}
1487+
else if let Value::Projection(_index, ProjectionElem::Deref) = value {
1488+
return None;
14951489
}
1496-
_ => {}
14971490
}
14981491

1499-
let op = self.evaluated[index].as_ref()?;
1500-
15011492
let value = op_to_prop_const(&mut self.ecx, op)?;
15021493

15031494
// Check that we do not leak a pointer.

0 commit comments

Comments
 (0)