Skip to content

Commit 7246da3

Browse files
committed
rewrite ignore nested array condition
1 parent 550fb81 commit 7246da3

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

+17-26
Original file line numberDiff line numberDiff line change
@@ -1348,38 +1348,29 @@ impl<'tcx> VnState<'_, 'tcx> {
13481348
// This was already constant in MIR, do not change it.
13491349
let value = self.get(index);
13501350
debug!(?index, ?value);
1351-
match value {
1352-
// If the constant is not deterministic, adding an additional mention of it in MIR will
1353-
// not give the same value as the former mention.
1354-
Value::Constant { value, disambiguator: _ } if value.is_deterministic() => {
1355-
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: *value });
1356-
}
1351+
// If the constant is not deterministic, adding an additional mention of it in MIR will
1352+
// not give the same value as the former mention.
1353+
if let Value::Constant { value, disambiguator: _ } = value
1354+
&& value.is_deterministic()
1355+
{
1356+
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: *value });
1357+
}
1358+
1359+
let op = self.evaluated[index].as_ref()?;
1360+
1361+
if let Either::Left(mplace) = op.as_mplace_or_imm()
1362+
&& let ty::Array(ty, _const) = mplace.layout.ty.kind()
1363+
{
13571364
// ignore nested arrays
1358-
Value::Aggregate(AggregateTy::Array, _, fields) => {
1359-
for f in fields {
1360-
if let Value::Constant { value: Const::Val(const_, _), .. } = self.get(*f)
1361-
&& let ConstValue::Indirect { .. } = const_
1362-
{
1363-
return None;
1364-
}
1365-
}
1365+
if ty.is_array() {
1366+
return None;
13661367
}
13671368
// ignore promoted arrays
1368-
Value::Projection(index, ProjectionElem::Deref) => {
1369-
if let Value::Constant { value: Const::Val(const_, ty), .. } = self.get(*index)
1370-
&& let ConstValue::Scalar(Scalar::Ptr(..)) = const_
1371-
&& let ty::Ref(region, ty, _mutability) = ty.kind()
1372-
&& region.is_erased()
1373-
&& ty.is_array()
1374-
{
1375-
return None;
1376-
}
1369+
else if let Value::Projection(_index, ProjectionElem::Deref) = value {
1370+
return None;
13771371
}
1378-
_ => {}
13791372
}
13801373

1381-
let op = self.evaluated[index].as_ref()?;
1382-
13831374
let value = op_to_prop_const(&mut self.ecx, op)?;
13841375

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

0 commit comments

Comments
 (0)