Promote unchecked_add/sub/mul/shl/shr to mir::BinOp
This commit is contained in:
parent
8d1fa473dd
commit
39788e07ba
36 changed files with 504 additions and 215 deletions
|
@ -132,7 +132,7 @@ pub fn build_langcall<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
// all shifts). For 32- and 64-bit types, this matches the semantics
|
||||
// of Java. (See related discussion on #1877 and #10183.)
|
||||
|
||||
pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
pub fn build_masked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
lhs: Bx::Value,
|
||||
rhs: Bx::Value,
|
||||
|
@ -143,7 +143,7 @@ pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
bx.shl(lhs, rhs)
|
||||
}
|
||||
|
||||
pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
pub fn build_masked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
lhs_t: Ty<'tcx>,
|
||||
lhs: Bx::Value,
|
||||
|
|
|
@ -798,6 +798,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
bx.add(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::AddUnchecked => {
|
||||
if is_signed {
|
||||
bx.unchecked_sadd(lhs, rhs)
|
||||
} else {
|
||||
bx.unchecked_uadd(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::Sub => {
|
||||
if is_float {
|
||||
bx.fsub(lhs, rhs)
|
||||
|
@ -805,6 +812,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
bx.sub(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::SubUnchecked => {
|
||||
if is_signed {
|
||||
bx.unchecked_ssub(lhs, rhs)
|
||||
} else {
|
||||
bx.unchecked_usub(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::Mul => {
|
||||
if is_float {
|
||||
bx.fmul(lhs, rhs)
|
||||
|
@ -812,6 +826,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
bx.mul(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::MulUnchecked => {
|
||||
if is_signed {
|
||||
bx.unchecked_smul(lhs, rhs)
|
||||
} else {
|
||||
bx.unchecked_umul(lhs, rhs)
|
||||
}
|
||||
}
|
||||
mir::BinOp::Div => {
|
||||
if is_float {
|
||||
bx.fdiv(lhs, rhs)
|
||||
|
@ -848,8 +869,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
bx.inbounds_gep(llty, lhs, &[rhs])
|
||||
}
|
||||
}
|
||||
mir::BinOp::Shl => common::build_unchecked_lshift(bx, lhs, rhs),
|
||||
mir::BinOp::Shr => common::build_unchecked_rshift(bx, input_ty, lhs, rhs),
|
||||
mir::BinOp::Shl => common::build_masked_lshift(bx, lhs, rhs),
|
||||
mir::BinOp::ShlUnchecked => {
|
||||
let rhs = base::cast_shift_expr_rhs(bx, lhs, rhs);
|
||||
bx.shl(lhs, rhs)
|
||||
}
|
||||
mir::BinOp::Shr => common::build_masked_rshift(bx, input_ty, lhs, rhs),
|
||||
mir::BinOp::ShrUnchecked => {
|
||||
let rhs = base::cast_shift_expr_rhs(bx, lhs, rhs);
|
||||
if is_signed { bx.ashr(lhs, rhs) } else { bx.lshr(lhs, rhs) }
|
||||
}
|
||||
mir::BinOp::Ne
|
||||
| mir::BinOp::Lt
|
||||
| mir::BinOp::Gt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue