Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rustc_mir: don't move temporaries that are still used later.
  • Loading branch information
eddyb committed Dec 5, 2017
1 parent fdfbcf8 commit 2a629f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/librustc/mir/mod.rs
Expand Up @@ -1347,6 +1347,12 @@ impl<'tcx> Operand<'tcx> {
})
}

pub fn to_copy(&self) -> Self {
match *self {
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
Operand::Move(ref place) => Operand::Copy(place.clone())
}
}
}

///////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/build/expr/as_rvalue.rs
Expand Up @@ -87,7 +87,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let is_min = this.temp(bool_ty, expr_span);

this.cfg.push_assign(block, source_info, &is_min,
Rvalue::BinaryOp(BinOp::Eq, arg.clone(), minval));
Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval));

let err = ConstMathErr::Overflow(Op::Neg);
block = this.assert(block, Operand::Move(is_min), false,
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let is_zero = self.temp(bool_ty, span);
let zero = self.zero_literal(span, ty);
self.cfg.push_assign(block, source_info, &is_zero,
Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), zero));
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero));

block = self.assert(block, Operand::Move(is_zero), false,
AssertMessage::Math(zero_err), span);
Expand All @@ -364,9 +364,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// this does (rhs == -1) & (lhs == MIN). It could short-circuit instead

self.cfg.push_assign(block, source_info, &is_neg_1,
Rvalue::BinaryOp(BinOp::Eq, rhs.clone(), neg_1));
Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1));
self.cfg.push_assign(block, source_info, &is_min,
Rvalue::BinaryOp(BinOp::Eq, lhs.clone(), min));
Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min));

let is_neg_1 = Operand::Move(is_neg_1);
let is_min = Operand::Move(is_min);
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/i128.rs
Expand Up @@ -10,6 +10,8 @@

// ignore-emscripten i128 doesn't work

// compile-flags: -Z borrowck=compare

#![feature(i128_type, test)]

extern crate test;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/u128.rs
Expand Up @@ -10,6 +10,8 @@

// ignore-emscripten u128 not supported

// compile-flags: -Z borrowck=compare

#![feature(i128_type, test)]

extern crate test;
Expand Down

0 comments on commit 2a629f9

Please sign in to comment.