Auto merge of #82727 - oli-obk:shrinkmem, r=pnkfelix

Test the effect of shrinking the size of Rvalue by 16 bytes

r? `@ghost`
This commit is contained in:
bors 2021-03-08 08:39:24 +00:00
commit 27885a94c6
29 changed files with 94 additions and 66 deletions

View File

@ -464,14 +464,14 @@ fn codegen_stmt<'tcx>(
let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout()); let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout());
lval.write_cvalue(fx, val); lval.write_cvalue(fx, val);
} }
Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => { Rvalue::BinaryOp(bin_op, box (ref lhs, ref rhs)) => {
let lhs = codegen_operand(fx, lhs); let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs); let rhs = codegen_operand(fx, rhs);
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs); let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
lval.write_cvalue(fx, res); lval.write_cvalue(fx, res);
} }
Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => { Rvalue::CheckedBinaryOp(bin_op, box (ref lhs, ref rhs)) => {
let lhs = codegen_operand(fx, lhs); let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs); let rhs = codegen_operand(fx, rhs);

View File

@ -5,6 +5,7 @@
associated_type_bounds, associated_type_bounds,
never_type, never_type,
try_blocks, try_blocks,
box_patterns,
hash_drain_filter hash_drain_filter
)] )]
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]

View File

@ -424,7 +424,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, operand) (bx, operand)
} }
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => { mir::Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
let lhs = self.codegen_operand(&mut bx, lhs); let lhs = self.codegen_operand(&mut bx, lhs);
let rhs = self.codegen_operand(&mut bx, rhs); let rhs = self.codegen_operand(&mut bx, rhs);
let llresult = match (lhs.val, rhs.val) { let llresult = match (lhs.val, rhs.val) {
@ -453,7 +453,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}; };
(bx, operand) (bx, operand)
} }
mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { mir::Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
let lhs = self.codegen_operand(&mut bx, lhs); let lhs = self.codegen_operand(&mut bx, lhs);
let rhs = self.codegen_operand(&mut bx, rhs); let rhs = self.codegen_operand(&mut bx, rhs);
let result = self.codegen_scalar_checked_binop( let result = self.codegen_scalar_checked_binop(

View File

@ -1683,6 +1683,9 @@ pub struct Place<'tcx> {
pub projection: &'tcx List<PlaceElem<'tcx>>, pub projection: &'tcx List<PlaceElem<'tcx>>,
} }
#[cfg(target_arch = "x86_64")]
static_assert_size!(Place<'_>, 16);
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(TyEncodable, TyDecodable, HashStable)] #[derive(TyEncodable, TyDecodable, HashStable)]
pub enum ProjectionElem<V, T> { pub enum ProjectionElem<V, T> {
@ -1981,6 +1984,9 @@ pub enum Operand<'tcx> {
Constant(Box<Constant<'tcx>>), Constant(Box<Constant<'tcx>>),
} }
#[cfg(target_arch = "x86_64")]
static_assert_size!(Operand<'_>, 24);
impl<'tcx> Debug for Operand<'tcx> { impl<'tcx> Debug for Operand<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
use self::Operand::*; use self::Operand::*;
@ -2096,8 +2102,8 @@ pub enum Rvalue<'tcx> {
Cast(CastKind, Operand<'tcx>, Ty<'tcx>), Cast(CastKind, Operand<'tcx>, Ty<'tcx>),
BinaryOp(BinOp, Operand<'tcx>, Operand<'tcx>), BinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
CheckedBinaryOp(BinOp, Operand<'tcx>, Operand<'tcx>), CheckedBinaryOp(BinOp, Box<(Operand<'tcx>, Operand<'tcx>)>),
NullaryOp(NullOp, Ty<'tcx>), NullaryOp(NullOp, Ty<'tcx>),
UnaryOp(UnOp, Operand<'tcx>), UnaryOp(UnOp, Operand<'tcx>),
@ -2116,6 +2122,9 @@ pub enum Rvalue<'tcx> {
Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>), Aggregate(Box<AggregateKind<'tcx>>, Vec<Operand<'tcx>>),
} }
#[cfg(target_arch = "x86_64")]
static_assert_size!(Rvalue<'_>, 40);
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum CastKind { pub enum CastKind {
Misc, Misc,
@ -2139,6 +2148,9 @@ pub enum AggregateKind<'tcx> {
Generator(DefId, SubstsRef<'tcx>, hir::Movability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
} }
#[cfg(target_arch = "x86_64")]
static_assert_size!(AggregateKind<'_>, 48);
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum BinOp { pub enum BinOp {
/// The `+` operator (addition) /// The `+` operator (addition)
@ -2215,8 +2227,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
Cast(ref kind, ref place, ref ty) => { Cast(ref kind, ref place, ref ty) => {
write!(fmt, "{:?} as {:?} ({:?})", place, ty, kind) write!(fmt, "{:?} as {:?} ({:?})", place, ty, kind)
} }
BinaryOp(ref op, ref a, ref b) => write!(fmt, "{:?}({:?}, {:?})", op, a, b), BinaryOp(ref op, box (ref a, ref b)) => write!(fmt, "{:?}({:?}, {:?})", op, a, b),
CheckedBinaryOp(ref op, ref a, ref b) => { CheckedBinaryOp(ref op, box (ref a, ref b)) => {
write!(fmt, "Checked{:?}({:?}, {:?})", op, a, b) write!(fmt, "Checked{:?}({:?}, {:?})", op, a, b)
} }
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a), UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),

View File

@ -182,12 +182,12 @@ impl<'tcx> Rvalue<'tcx> {
} }
Rvalue::Len(..) => tcx.types.usize, Rvalue::Len(..) => tcx.types.usize,
Rvalue::Cast(.., ty) => ty, Rvalue::Cast(.., ty) => ty,
Rvalue::BinaryOp(op, ref lhs, ref rhs) => { Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
let lhs_ty = lhs.ty(local_decls, tcx); let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx);
op.ty(tcx, lhs_ty, rhs_ty) op.ty(tcx, lhs_ty, rhs_ty)
} }
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
let lhs_ty = lhs.ty(local_decls, tcx); let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx);
let ty = op.ty(tcx, lhs_ty, rhs_ty); let ty = op.ty(tcx, lhs_ty, rhs_ty);

View File

@ -181,9 +181,11 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
AddressOf(mutability, place) => AddressOf(mutability, place.fold_with(folder)), AddressOf(mutability, place) => AddressOf(mutability, place.fold_with(folder)),
Len(place) => Len(place.fold_with(folder)), Len(place) => Len(place.fold_with(folder)),
Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)), Cast(kind, op, ty) => Cast(kind, op.fold_with(folder), ty.fold_with(folder)),
BinaryOp(op, rhs, lhs) => BinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)), BinaryOp(op, box (rhs, lhs)) => {
CheckedBinaryOp(op, rhs, lhs) => { BinaryOp(op, box (rhs.fold_with(folder), lhs.fold_with(folder)))
CheckedBinaryOp(op, rhs.fold_with(folder), lhs.fold_with(folder)) }
CheckedBinaryOp(op, box (rhs, lhs)) => {
CheckedBinaryOp(op, box (rhs.fold_with(folder), lhs.fold_with(folder)))
} }
UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)), UnaryOp(op, val) => UnaryOp(op, val.fold_with(folder)),
Discriminant(place) => Discriminant(place.fold_with(folder)), Discriminant(place) => Discriminant(place.fold_with(folder)),
@ -227,7 +229,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
op.visit_with(visitor)?; op.visit_with(visitor)?;
ty.visit_with(visitor) ty.visit_with(visitor)
} }
BinaryOp(_, ref rhs, ref lhs) | CheckedBinaryOp(_, ref rhs, ref lhs) => { BinaryOp(_, box (ref rhs, ref lhs)) | CheckedBinaryOp(_, box (ref rhs, ref lhs)) => {
rhs.visit_with(visitor)?; rhs.visit_with(visitor)?;
lhs.visit_with(visitor) lhs.visit_with(visitor)
} }

View File

@ -687,8 +687,8 @@ macro_rules! make_mir_visitor {
self.visit_ty(ty, TyContext::Location(location)); self.visit_ty(ty, TyContext::Location(location));
} }
Rvalue::BinaryOp(_bin_op, lhs, rhs) Rvalue::BinaryOp(_bin_op, box(lhs, rhs))
| Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => { | Rvalue::CheckedBinaryOp(_bin_op, box(lhs, rhs)) => {
self.visit_operand(lhs, location); self.visit_operand(lhs, location);
self.visit_operand(rhs, location); self.visit_operand(rhs, location);
} }

View File

@ -326,8 +326,8 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
); );
} }
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) Rvalue::BinaryOp(_bin_op, box (ref operand1, ref operand2))
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { | Rvalue::CheckedBinaryOp(_bin_op, box (ref operand1, ref operand2)) => {
self.consume_operand(location, operand1); self.consume_operand(location, operand1);
self.consume_operand(location, operand2); self.consume_operand(location, operand2);
} }

View File

@ -1316,8 +1316,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
); );
} }
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) Rvalue::BinaryOp(_bin_op, box (ref operand1, ref operand2))
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { | Rvalue::CheckedBinaryOp(_bin_op, box (ref operand1, ref operand2)) => {
self.consume_operand(location, (operand1, span), flow_state); self.consume_operand(location, (operand1, span), flow_state);
self.consume_operand(location, (operand2, span), flow_state); self.consume_operand(location, (operand2, span), flow_state);
} }

View File

@ -2299,8 +2299,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge, BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
left, box (left, right),
right,
) => { ) => {
let ty_left = left.ty(body, tcx); let ty_left = left.ty(body, tcx);
match ty_left.kind() { match ty_left.kind() {

View File

@ -329,8 +329,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
| Rvalue::Repeat(ref operand, _) | Rvalue::Repeat(ref operand, _)
| Rvalue::Cast(_, ref operand, _) | Rvalue::Cast(_, ref operand, _)
| Rvalue::UnaryOp(_, ref operand) => self.gather_operand(operand), | Rvalue::UnaryOp(_, ref operand) => self.gather_operand(operand),
Rvalue::BinaryOp(ref _binop, ref lhs, ref rhs) Rvalue::BinaryOp(ref _binop, box (ref lhs, ref rhs))
| Rvalue::CheckedBinaryOp(ref _binop, ref lhs, ref rhs) => { | Rvalue::CheckedBinaryOp(ref _binop, box (ref lhs, ref rhs)) => {
self.gather_operand(lhs); self.gather_operand(lhs);
self.gather_operand(rhs); self.gather_operand(rhs);
} }

View File

@ -165,7 +165,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.copy_op(&op, &dest)?; self.copy_op(&op, &dest)?;
} }
BinaryOp(bin_op, ref left, ref right) => { BinaryOp(bin_op, box (ref left, ref right)) => {
let layout = binop_left_homogeneous(bin_op).then_some(dest.layout); let layout = binop_left_homogeneous(bin_op).then_some(dest.layout);
let left = self.read_immediate(&self.eval_operand(left, layout)?)?; let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
let layout = binop_right_homogeneous(bin_op).then_some(left.layout); let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
@ -173,7 +173,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?; self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
} }
CheckedBinaryOp(bin_op, ref left, ref right) => { CheckedBinaryOp(bin_op, box (ref left, ref right)) => {
// Due to the extra boolean in the result, we can never reuse the `dest.layout`. // Due to the extra boolean in the result, we can never reuse the `dest.layout`.
let left = self.read_immediate(&self.eval_operand(left, None)?)?; let left = self.read_immediate(&self.eval_operand(left, None)?)?;
let layout = binop_right_homogeneous(bin_op).then_some(left.layout); let layout = binop_right_homogeneous(bin_op).then_some(left.layout);

View File

@ -463,7 +463,7 @@ impl CloneShimBuilder<'tcx> {
let cond = self.make_place(Mutability::Mut, tcx.types.bool); let cond = self.make_place(Mutability::Mut, tcx.types.bool);
let compute_cond = self.make_statement(StatementKind::Assign(box ( let compute_cond = self.make_statement(StatementKind::Assign(box (
cond, cond,
Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg)), Rvalue::BinaryOp(BinOp::Ne, box (Operand::Copy(end), Operand::Copy(beg))),
))); )));
// `if end != beg { goto loop_body; } else { goto loop_end; }` // `if end != beg { goto loop_body; } else { goto loop_end; }`
@ -536,8 +536,7 @@ impl CloneShimBuilder<'tcx> {
Place::from(beg), Place::from(beg),
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::Add, BinOp::Add,
Operand::Copy(Place::from(beg)), box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
Operand::Constant(self.make_usize(1)),
), ),
)))]; )))];
self.block(statements, TerminatorKind::Goto { target: BasicBlock::new(1) }, false); self.block(statements, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
@ -590,8 +589,7 @@ impl CloneShimBuilder<'tcx> {
Place::from(beg), Place::from(beg),
Rvalue::BinaryOp( Rvalue::BinaryOp(
BinOp::Add, BinOp::Add,
Operand::Copy(Place::from(beg)), box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
Operand::Constant(self.make_usize(1)),
), ),
))); )));
self.block(vec![statement], TerminatorKind::Goto { target: BasicBlock::new(6) }, true); self.block(vec![statement], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);

View File

@ -168,7 +168,7 @@ where
| Rvalue::UnaryOp(_, operand) | Rvalue::UnaryOp(_, operand)
| Rvalue::Cast(_, operand, _) => in_operand::<Q, _>(cx, in_local, operand), | Rvalue::Cast(_, operand, _) => in_operand::<Q, _>(cx, in_local, operand),
Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => {
in_operand::<Q, _>(cx, in_local, lhs) || in_operand::<Q, _>(cx, in_local, rhs) in_operand::<Q, _>(cx, in_local, lhs) || in_operand::<Q, _>(cx, in_local, rhs)
} }

View File

@ -684,8 +684,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
} }
} }
Rvalue::BinaryOp(op, ref lhs, ref rhs) Rvalue::BinaryOp(op, box (ref lhs, ref rhs))
| Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { | Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
let lhs_ty = lhs.ty(self.body, self.tcx); let lhs_ty = lhs.ty(self.body, self.tcx);
let rhs_ty = rhs.ty(self.body, self.tcx); let rhs_ty = rhs.ty(self.body, self.tcx);

View File

@ -676,11 +676,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg); trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);
self.check_unary_op(*op, arg, source_info)?; self.check_unary_op(*op, arg, source_info)?;
} }
Rvalue::BinaryOp(op, left, right) => { Rvalue::BinaryOp(op, box (left, right)) => {
trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right); trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right);
self.check_binary_op(*op, left, right, source_info)?; self.check_binary_op(*op, left, right, source_info)?;
} }
Rvalue::CheckedBinaryOp(op, left, right) => { Rvalue::CheckedBinaryOp(op, box (left, right)) => {
trace!( trace!(
"checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {:?})", "checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {:?})",
op, op,
@ -740,7 +740,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) -> Option<()> { ) -> Option<()> {
self.use_ecx(|this| { self.use_ecx(|this| {
match rvalue { match rvalue {
Rvalue::BinaryOp(op, left, right) | Rvalue::CheckedBinaryOp(op, left, right) => { Rvalue::BinaryOp(op, box (left, right))
| Rvalue::CheckedBinaryOp(op, box (left, right)) => {
let l = this.ecx.eval_operand(left, None); let l = this.ecx.eval_operand(left, None);
let r = this.ecx.eval_operand(right, None); let r = this.ecx.eval_operand(right, None);
@ -772,7 +773,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
} }
BinOp::Mul => { BinOp::Mul => {
if const_arg.layout.ty.is_integral() && arg_value == 0 { if const_arg.layout.ty.is_integral() && arg_value == 0 {
if let Rvalue::CheckedBinaryOp(_, _, _) = rvalue { if let Rvalue::CheckedBinaryOp(_, _) = rvalue {
let val = Immediate::ScalarPair( let val = Immediate::ScalarPair(
const_arg.to_scalar()?.into(), const_arg.to_scalar()?.into(),
Scalar::from_bool(false).into(), Scalar::from_bool(false).into(),

View File

@ -91,8 +91,10 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
opt_to_apply.infos[0].first_switch_info.discr_used_in_switch; opt_to_apply.infos[0].first_switch_info.discr_used_in_switch;
let not_equal_rvalue = Rvalue::BinaryOp( let not_equal_rvalue = Rvalue::BinaryOp(
not_equal, not_equal,
box (
Operand::Copy(Place::from(second_discriminant_temp)), Operand::Copy(Place::from(second_discriminant_temp)),
Operand::Copy(first_descriminant_place), Operand::Copy(first_descriminant_place),
),
); );
patch.add_statement( patch.add_statement(
end_of_block_location, end_of_block_location,

View File

@ -44,7 +44,7 @@ impl<'tcx, 'a> InstCombineContext<'tcx, 'a> {
/// Transform boolean comparisons into logical operations. /// Transform boolean comparisons into logical operations.
fn combine_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { fn combine_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
match rvalue { match rvalue {
Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), a, b) => { Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), box (a, b)) => {
let new = match (op, self.try_eval_bool(a), self.try_eval_bool(b)) { let new = match (op, self.try_eval_bool(a), self.try_eval_bool(b)) {
// Transform "Eq(a, true)" ==> "a" // Transform "Eq(a, true)" ==> "a"
(BinOp::Eq, _, Some(true)) => Some(a.clone()), (BinOp::Eq, _, Some(true)) => Some(a.clone()),

View File

@ -59,7 +59,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
source_info: terminator.source_info, source_info: terminator.source_info,
kind: StatementKind::Assign(box ( kind: StatementKind::Assign(box (
destination, destination,
Rvalue::BinaryOp(bin_op, lhs, rhs), Rvalue::BinaryOp(bin_op, box (lhs, rhs)),
)), )),
}); });
terminator.kind = TerminatorKind::Goto { target }; terminator.kind = TerminatorKind::Goto { target };

View File

@ -139,8 +139,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
let op = if f_b { BinOp::Eq } else { BinOp::Ne }; let op = if f_b { BinOp::Eq } else { BinOp::Ne };
let rhs = Rvalue::BinaryOp( let rhs = Rvalue::BinaryOp(
op, op,
Operand::Copy(Place::from(discr_local)), box (Operand::Copy(Place::from(discr_local)), const_cmp),
const_cmp,
); );
Statement { Statement {
source_info: f.source_info, source_info: f.source_info,

View File

@ -643,7 +643,7 @@ impl<'tcx> Validator<'_, 'tcx> {
self.validate_operand(operand)?; self.validate_operand(operand)?;
} }
Rvalue::BinaryOp(op, lhs, rhs) | Rvalue::CheckedBinaryOp(op, lhs, rhs) => { Rvalue::BinaryOp(op, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(op, box (lhs, rhs)) => {
let op = *op; let op = *op;
let lhs_ty = lhs.ty(self.body, self.tcx); let lhs_ty = lhs.ty(self.body, self.tcx);

View File

@ -84,10 +84,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
use Operand::*; use Operand::*;
match rhs { match rhs {
Rvalue::BinaryOp(_, ref mut left @ Move(_), Constant(_)) => { Rvalue::BinaryOp(_, box (ref mut left @ Move(_), Constant(_))) => {
*left = Copy(opt.to_switch_on); *left = Copy(opt.to_switch_on);
} }
Rvalue::BinaryOp(_, Constant(_), ref mut right @ Move(_)) => { Rvalue::BinaryOp(_, box (Constant(_), ref mut right @ Move(_))) => {
*right = Copy(opt.to_switch_on); *right = Copy(opt.to_switch_on);
} }
_ => (), _ => (),
@ -166,7 +166,10 @@ impl<'a, 'tcx> OptimizationFinder<'a, 'tcx> {
if *lhs == place_switched_on => if *lhs == place_switched_on =>
{ {
match rhs { match rhs {
Rvalue::BinaryOp(op @ (BinOp::Eq | BinOp::Ne), left, right) => { Rvalue::BinaryOp(
op @ (BinOp::Eq | BinOp::Ne),
box (left, right),
) => {
let (branch_value_scalar, branch_value_ty, to_switch_on) = let (branch_value_scalar, branch_value_ty, to_switch_on) =
find_branch_value_info(left, right)?; find_branch_value_info(left, right)?;

View File

@ -678,11 +678,14 @@ where
let one = self.constant_usize(1); let one = self.constant_usize(1);
let (ptr_next, cur_next) = if ptr_based { let (ptr_next, cur_next) = if ptr_based {
(Rvalue::Use(copy(cur.into())), Rvalue::BinaryOp(BinOp::Offset, move_(cur.into()), one)) (
Rvalue::Use(copy(cur.into())),
Rvalue::BinaryOp(BinOp::Offset, box (move_(cur.into()), one)),
)
} else { } else {
( (
Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place, cur)), Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place, cur)),
Rvalue::BinaryOp(BinOp::Add, move_(cur.into()), one), Rvalue::BinaryOp(BinOp::Add, box (move_(cur.into()), one)),
) )
}; };
@ -700,7 +703,7 @@ where
let loop_block = BasicBlockData { let loop_block = BasicBlockData {
statements: vec![self.assign( statements: vec![self.assign(
can_go, can_go,
Rvalue::BinaryOp(BinOp::Eq, copy(Place::from(cur)), copy(length_or_end)), Rvalue::BinaryOp(BinOp::Eq, box (copy(Place::from(cur)), copy(length_or_end))),
)], )],
is_cleanup: unwind.is_cleanup(), is_cleanup: unwind.is_cleanup(),
terminator: Some(Terminator { terminator: Some(Terminator {
@ -816,7 +819,10 @@ where
self.assign(cur, Rvalue::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)), self.assign(cur, Rvalue::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)),
self.assign( self.assign(
length_or_end, length_or_end,
Rvalue::BinaryOp(BinOp::Offset, Operand::Copy(cur), Operand::Move(length)), Rvalue::BinaryOp(
BinOp::Offset,
box (Operand::Copy(cur), Operand::Move(length)),
),
), ),
] ]
} else { } else {

View File

@ -667,7 +667,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
lt, lt,
Rvalue::BinaryOp(BinOp::Lt, Operand::Copy(Place::from(index)), Operand::Copy(len)), Rvalue::BinaryOp(
BinOp::Lt,
box (Operand::Copy(Place::from(index)), Operand::Copy(len)),
),
); );
let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) }; let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) };
// assert!(lt, "...") // assert!(lt, "...")

View File

@ -81,7 +81,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
is_min, is_min,
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval), Rvalue::BinaryOp(BinOp::Eq, box (arg.to_copy(), minval)),
); );
block = this.assert( block = this.assert(
@ -291,7 +291,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
result_value, result_value,
Rvalue::CheckedBinaryOp(op, lhs.to_copy(), rhs.to_copy()), Rvalue::CheckedBinaryOp(op, box (lhs.to_copy(), rhs.to_copy())),
); );
let val_fld = Field::new(0); let val_fld = Field::new(0);
let of_fld = Field::new(1); let of_fld = Field::new(1);
@ -324,7 +324,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
is_zero, is_zero,
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero), Rvalue::BinaryOp(BinOp::Eq, box (rhs.to_copy(), zero)),
); );
block = self.assert(block, Operand::Move(is_zero), false, zero_err, span); block = self.assert(block, Operand::Move(is_zero), false, zero_err, span);
@ -345,13 +345,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
is_neg_1, is_neg_1,
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1), Rvalue::BinaryOp(BinOp::Eq, box (rhs.to_copy(), neg_1)),
); );
self.cfg.push_assign( self.cfg.push_assign(
block, block,
source_info, source_info,
is_min, is_min,
Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min), Rvalue::BinaryOp(BinOp::Eq, box (lhs.to_copy(), min)),
); );
let is_neg_1 = Operand::Move(is_neg_1); let is_neg_1 = Operand::Move(is_neg_1);
@ -360,14 +360,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block, block,
source_info, source_info,
of, of,
Rvalue::BinaryOp(BinOp::BitAnd, is_neg_1, is_min), Rvalue::BinaryOp(BinOp::BitAnd, box (is_neg_1, is_min)),
); );
block = self.assert(block, Operand::Move(of), false, overflow_err, span); block = self.assert(block, Operand::Move(of), false, overflow_err, span);
} }
} }
block.and(Rvalue::BinaryOp(op, lhs, rhs)) block.and(Rvalue::BinaryOp(op, box (lhs, rhs)))
} }
} }

View File

@ -335,7 +335,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let result = self.temp(bool_ty, source_info.span); let result = self.temp(bool_ty, source_info.span);
// result = op(left, right) // result = op(left, right)
self.cfg.push_assign(block, source_info, result, Rvalue::BinaryOp(op, left, right)); self.cfg.push_assign(block, source_info, result, Rvalue::BinaryOp(op, box (left, right)));
// branch based on result // branch based on result
self.cfg.terminate( self.cfg.terminate(

View File

@ -411,7 +411,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
self.locals[local] = self.operand_to_node(span, operand)?; self.locals[local] = self.operand_to_node(span, operand)?;
Ok(()) Ok(())
} }
Rvalue::BinaryOp(op, ref lhs, ref rhs) if Self::check_binop(op) => { Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) if Self::check_binop(op) => {
let lhs = self.operand_to_node(span, lhs)?; let lhs = self.operand_to_node(span, lhs)?;
let rhs = self.operand_to_node(span, rhs)?; let rhs = self.operand_to_node(span, rhs)?;
self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs), span); self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs), span);
@ -421,7 +421,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
Ok(()) Ok(())
} }
} }
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) if Self::check_binop(op) => { Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs))
if Self::check_binop(op) =>
{
let lhs = self.operand_to_node(span, lhs)?; let lhs = self.operand_to_node(span, lhs)?;
let rhs = self.operand_to_node(span, rhs)?; let rhs = self.operand_to_node(span, rhs)?;
self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs), span); self.locals[local] = self.add_node(Node::Binop(op, lhs, rhs), span);

View File

@ -584,10 +584,10 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
match rvalue { match rvalue {
Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op), Use(op) | Repeat(op, _) | Cast(_, op, _) | UnaryOp(_, op) => visit_op(op),
Aggregate(_, ops) => ops.iter().for_each(visit_op), Aggregate(_, ops) => ops.iter().for_each(visit_op),
BinaryOp(_, lhs, rhs) | CheckedBinaryOp(_, lhs, rhs) => { BinaryOp(_, box (lhs, rhs)) | CheckedBinaryOp(_, box (lhs, rhs)) => {
visit_op(lhs); visit_op(lhs);
visit_op(rhs); visit_op(rhs);
}, }
_ => (), _ => (),
} }
} }

View File

@ -172,7 +172,7 @@ fn check_rvalue(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, rvalue: &Rv
} }
}, },
// binops are fine on integers // binops are fine on integers
Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => {
check_operand(tcx, lhs, span, body)?; check_operand(tcx, lhs, span, body)?;
check_operand(tcx, rhs, span, body)?; check_operand(tcx, rhs, span, body)?;
let ty = lhs.ty(body, tcx); let ty = lhs.ty(body, tcx);