Shrink the size of Rvalue by 16 bytes
This commit is contained in:
parent
f31481368b
commit
9a2362e5a9
29 changed files with 83 additions and 67 deletions
|
@ -326,8 +326,8 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
|
||||
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
|
||||
Rvalue::BinaryOp(_bin_op, box (ref operand1, ref operand2))
|
||||
| Rvalue::CheckedBinaryOp(_bin_op, box (ref operand1, ref operand2)) => {
|
||||
self.consume_operand(location, operand1);
|
||||
self.consume_operand(location, operand2);
|
||||
}
|
||||
|
|
|
@ -1316,8 +1316,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
|
||||
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
|
||||
Rvalue::BinaryOp(_bin_op, box (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, (operand2, span), flow_state);
|
||||
}
|
||||
|
|
|
@ -2299,8 +2299,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
|
||||
Rvalue::BinaryOp(
|
||||
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge,
|
||||
left,
|
||||
right,
|
||||
box (left, right),
|
||||
) => {
|
||||
let ty_left = left.ty(body, tcx);
|
||||
match ty_left.kind() {
|
||||
|
|
|
@ -329,8 +329,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
|
|||
| Rvalue::Repeat(ref operand, _)
|
||||
| Rvalue::Cast(_, ref operand, _)
|
||||
| Rvalue::UnaryOp(_, ref operand) => self.gather_operand(operand),
|
||||
Rvalue::BinaryOp(ref _binop, ref lhs, ref rhs)
|
||||
| Rvalue::CheckedBinaryOp(ref _binop, ref lhs, ref rhs) => {
|
||||
Rvalue::BinaryOp(ref _binop, box (ref lhs, ref rhs))
|
||||
| Rvalue::CheckedBinaryOp(ref _binop, box (ref lhs, ref rhs)) => {
|
||||
self.gather_operand(lhs);
|
||||
self.gather_operand(rhs);
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
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 left = self.read_immediate(&self.eval_operand(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)?;
|
||||
}
|
||||
|
||||
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`.
|
||||
let left = self.read_immediate(&self.eval_operand(left, None)?)?;
|
||||
let layout = binop_right_homogeneous(bin_op).then_some(left.layout);
|
||||
|
|
|
@ -463,7 +463,7 @@ impl CloneShimBuilder<'tcx> {
|
|||
let cond = self.make_place(Mutability::Mut, tcx.types.bool);
|
||||
let compute_cond = self.make_statement(StatementKind::Assign(box (
|
||||
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; }`
|
||||
|
@ -536,8 +536,7 @@ impl CloneShimBuilder<'tcx> {
|
|||
Place::from(beg),
|
||||
Rvalue::BinaryOp(
|
||||
BinOp::Add,
|
||||
Operand::Copy(Place::from(beg)),
|
||||
Operand::Constant(self.make_usize(1)),
|
||||
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
|
||||
),
|
||||
)))];
|
||||
self.block(statements, TerminatorKind::Goto { target: BasicBlock::new(1) }, false);
|
||||
|
@ -590,8 +589,7 @@ impl CloneShimBuilder<'tcx> {
|
|||
Place::from(beg),
|
||||
Rvalue::BinaryOp(
|
||||
BinOp::Add,
|
||||
Operand::Copy(Place::from(beg)),
|
||||
Operand::Constant(self.make_usize(1)),
|
||||
box (Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1))),
|
||||
),
|
||||
)));
|
||||
self.block(vec![statement], TerminatorKind::Goto { target: BasicBlock::new(6) }, true);
|
||||
|
|
|
@ -168,7 +168,7 @@ where
|
|||
| Rvalue::UnaryOp(_, 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -684,8 +684,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
Rvalue::BinaryOp(op, ref lhs, ref rhs)
|
||||
| Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
|
||||
Rvalue::BinaryOp(op, box (ref lhs, ref rhs))
|
||||
| Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
|
||||
let lhs_ty = lhs.ty(self.body, self.tcx);
|
||||
let rhs_ty = rhs.ty(self.body, self.tcx);
|
||||
|
||||
|
|
|
@ -676,11 +676,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);
|
||||
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);
|
||||
self.check_binary_op(*op, left, right, source_info)?;
|
||||
}
|
||||
Rvalue::CheckedBinaryOp(op, left, right) => {
|
||||
Rvalue::CheckedBinaryOp(op, box (left, right)) => {
|
||||
trace!(
|
||||
"checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {:?})",
|
||||
op,
|
||||
|
@ -740,7 +740,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
) -> Option<()> {
|
||||
self.use_ecx(|this| {
|
||||
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 r = this.ecx.eval_operand(right, None);
|
||||
|
||||
|
@ -772,7 +773,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
}
|
||||
BinOp::Mul => {
|
||||
if const_arg.layout.ty.is_integral() && arg_value == 0 {
|
||||
if let Rvalue::CheckedBinaryOp(_, _, _) = rvalue {
|
||||
if let Rvalue::CheckedBinaryOp(_, _) = rvalue {
|
||||
let val = Immediate::ScalarPair(
|
||||
const_arg.to_scalar()?.into(),
|
||||
Scalar::from_bool(false).into(),
|
||||
|
|
|
@ -91,8 +91,10 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
|||
opt_to_apply.infos[0].first_switch_info.discr_used_in_switch;
|
||||
let not_equal_rvalue = Rvalue::BinaryOp(
|
||||
not_equal,
|
||||
Operand::Copy(Place::from(second_discriminant_temp)),
|
||||
Operand::Copy(first_descriminant_place),
|
||||
box (
|
||||
Operand::Copy(Place::from(second_discriminant_temp)),
|
||||
Operand::Copy(first_descriminant_place),
|
||||
),
|
||||
);
|
||||
patch.add_statement(
|
||||
end_of_block_location,
|
||||
|
|
|
@ -44,7 +44,7 @@ impl<'tcx, 'a> InstCombineContext<'tcx, 'a> {
|
|||
/// Transform boolean comparisons into logical operations.
|
||||
fn combine_bool_cmp(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) {
|
||||
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)) {
|
||||
// Transform "Eq(a, true)" ==> "a"
|
||||
(BinOp::Eq, _, Some(true)) => Some(a.clone()),
|
||||
|
|
|
@ -59,7 +59,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
|
|||
source_info: terminator.source_info,
|
||||
kind: StatementKind::Assign(box (
|
||||
destination,
|
||||
Rvalue::BinaryOp(bin_op, lhs, rhs),
|
||||
Rvalue::BinaryOp(bin_op, box (lhs, rhs)),
|
||||
)),
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
|
|
|
@ -139,8 +139,7 @@ impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
|||
let op = if f_b { BinOp::Eq } else { BinOp::Ne };
|
||||
let rhs = Rvalue::BinaryOp(
|
||||
op,
|
||||
Operand::Copy(Place::from(discr_local)),
|
||||
const_cmp,
|
||||
box (Operand::Copy(Place::from(discr_local)), const_cmp),
|
||||
);
|
||||
Statement {
|
||||
source_info: f.source_info,
|
||||
|
|
|
@ -643,7 +643,7 @@ impl<'tcx> Validator<'_, 'tcx> {
|
|||
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 lhs_ty = lhs.ty(self.body, self.tcx);
|
||||
|
||||
|
|
|
@ -84,10 +84,10 @@ impl<'tcx> MirPass<'tcx> for SimplifyComparisonIntegral {
|
|||
|
||||
use Operand::*;
|
||||
match rhs {
|
||||
Rvalue::BinaryOp(_, ref mut left @ Move(_), Constant(_)) => {
|
||||
Rvalue::BinaryOp(_, box (ref mut left @ Move(_), Constant(_))) => {
|
||||
*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);
|
||||
}
|
||||
_ => (),
|
||||
|
@ -166,7 +166,10 @@ impl<'a, 'tcx> OptimizationFinder<'a, 'tcx> {
|
|||
if *lhs == place_switched_on =>
|
||||
{
|
||||
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) =
|
||||
find_branch_value_info(left, right)?;
|
||||
|
||||
|
|
|
@ -678,11 +678,14 @@ where
|
|||
|
||||
let one = self.constant_usize(1);
|
||||
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 {
|
||||
(
|
||||
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 {
|
||||
statements: vec![self.assign(
|
||||
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(),
|
||||
terminator: Some(Terminator {
|
||||
|
@ -816,7 +819,10 @@ where
|
|||
self.assign(cur, Rvalue::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)),
|
||||
self.assign(
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue