@@ -816,7 +816,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
816
816
}
817
817
Operand :: Copy ( ref mut place) | Operand :: Move ( ref mut place) => {
818
818
let value = self . simplify_place_value ( place, location) ?;
819
- // Ignore arrays in operand .
819
+ // Ignore arrays in operands .
820
820
if let Value :: Aggregate ( AggregateTy :: Array , ..) = self . get ( value) {
821
821
return None ;
822
822
}
@@ -1492,14 +1492,6 @@ impl<'tcx> VnState<'_, 'tcx> {
1492
1492
if let Value :: Constant { value, disambiguator : _ } = value
1493
1493
&& value. is_deterministic ( )
1494
1494
{
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
- }
1503
1495
return Some ( ConstOperand { span : DUMMY_SP , user_ty : None , const_ : * value } ) ;
1504
1496
}
1505
1497
@@ -1566,7 +1558,19 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
1566
1558
let Some ( value) = value else { return } ;
1567
1559
1568
1560
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) {
1570
1574
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1571
1575
} else if let Some ( local) = self . try_as_local ( value, location)
1572
1576
&& * rvalue != Rvalue :: Use ( Operand :: Move ( local. into ( ) ) )
0 commit comments