Skip to content

Commit

Permalink
Simplify operands in unions.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 7, 2024
1 parent fc1a4c5 commit 69d51fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
}
}

let fields: Option<Vec<_>> = fields
.iter_mut()
.map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
.collect();
let fields = fields?;

let (ty, variant_index) = match *kind {
AggregateKind::Array(..) => {
assert!(!fields.is_empty());
Expand All @@ -912,12 +918,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
AggregateKind::Adt(_, _, _, _, Some(_)) => return None,
};

let fields: Option<Vec<_>> = fields
.iter_mut()
.map(|op| self.simplify_operand(op, location).or_else(|| self.new_opaque()))
.collect();
let fields = fields?;

if let AggregateTy::Array = ty
&& fields.len() > 4
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
StorageLive(_1);
StorageLive(_2);
- _2 = ();
- _1 = Union32 { value: move _2 };
+ _2 = const ();
_1 = Union32 { value: move _2 };
+ _1 = Union32 { value: const () };
StorageDead(_2);
_0 = move _1 as u32 (Transmute);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
StorageLive(_1);
StorageLive(_2);
- _2 = ();
- _1 = Union32 { value: move _2 };
+ _2 = const ();
_1 = Union32 { value: move _2 };
+ _1 = Union32 { value: const () };
StorageDead(_2);
_0 = move _1 as u32 (Transmute);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
let mut _0: ();
let _1: main::Un;
let mut _2: u32;
let mut _3: u32;
scope 1 {
debug un => _1;
scope 3 (inlined std::mem::drop::<u32>) {
debug _x => _3;
debug _x => _2;
}
}
scope 2 (inlined val) {
}

bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const 1_u32;
_1 = Un { us: const 1_u32 };
StorageLive(_2);
_2 = (_1.0: u32);
StorageDead(_2);
StorageLive(_3);
_3 = (_1.0: u32);
StorageDead(_3);
StorageDead(_1);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
let mut _0: ();
let _1: main::Un;
let mut _2: u32;
let mut _3: u32;
scope 1 {
debug un => _1;
scope 3 (inlined std::mem::drop::<u32>) {
debug _x => _3;
debug _x => _2;
}
}
scope 2 (inlined val) {
}

bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const 1_u32;
_1 = Un { us: const 1_u32 };
StorageLive(_2);
_2 = (_1.0: u32);
StorageDead(_2);
StorageLive(_3);
_3 = (_1.0: u32);
StorageDead(_3);
StorageDead(_1);
return;
}
Expand Down

0 comments on commit 69d51fc

Please sign in to comment.