Skip to content

Commit 5927e14

Browse files
committed
Simplify operands in unions.
1 parent d77734f commit 5927e14

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
865865
}
866866
}
867867

868+
let fields: Option<Vec<_>> = fields
869+
.iter_mut()
870+
.map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
871+
.collect();
872+
let fields = fields?;
873+
868874
let (ty, variant_index) = match *kind {
869875
AggregateKind::Array(..) => {
870876
assert!(!fields.is_empty());
@@ -884,12 +890,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
884890
AggregateKind::Adt(_, _, _, _, Some(_)) => return None,
885891
};
886892

887-
let fields: Option<Vec<_>> = fields
888-
.iter_mut()
889-
.map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
890-
.collect();
891-
let fields = fields?;
892-
893893
if let AggregateTy::Array = ty
894894
&& fields.len() > 4
895895
{

tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.32bit.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
StorageLive(_1);
1313
StorageLive(_2);
1414
- _2 = ();
15+
- _1 = Union32 { value: move _2 };
1516
+ _2 = const ();
16-
_1 = Union32 { value: move _2 };
17+
+ _1 = Union32 { value: const () };
1718
StorageDead(_2);
1819
_0 = move _1 as u32 (Transmute);
1920
StorageDead(_1);

tests/mir-opt/const_prop/transmute.undef_union_as_integer.GVN.64bit.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
StorageLive(_1);
1313
StorageLive(_2);
1414
- _2 = ();
15+
- _1 = Union32 { value: move _2 };
1516
+ _2 = const ();
16-
_1 = Union32 { value: move _2 };
17+
+ _1 = Union32 { value: const () };
1718
StorageDead(_2);
1819
_0 = move _1 as u32 (Transmute);
1920
StorageDead(_1);

0 commit comments

Comments
 (0)