Skip to content

Commit 1ac2d8f

Browse files
committed
Simplify operands in unions.
1 parent 8fb2777 commit 1ac2d8f

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
864864
}
865865
}
866866

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

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

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

+2-1
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

+2-1
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)