Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_mir: don't move temporaries that are still used later. #46492

Merged
merged 1 commit into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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