Promote unchecked_add/sub/mul/shl/shr to mir::BinOp
This commit is contained in:
parent
f429b3e67f
commit
9efe5e746a
@ -22,8 +22,8 @@ pub(crate) fn maybe_codegen<'tcx>(
|
|||||||
|
|
||||||
match bin_op {
|
match bin_op {
|
||||||
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => None,
|
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => None,
|
||||||
BinOp::Add | BinOp::Sub => None,
|
BinOp::Add | BinOp::AddUnchecked | BinOp::Sub | BinOp::SubUnchecked => None,
|
||||||
BinOp::Mul => {
|
BinOp::Mul | BinOp::MulUnchecked => {
|
||||||
let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)];
|
let args = [lhs.load_scalar(fx), rhs.load_scalar(fx)];
|
||||||
let ret_val = fx.lib_call(
|
let ret_val = fx.lib_call(
|
||||||
"__multi3",
|
"__multi3",
|
||||||
@ -69,7 +69,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => None,
|
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => None,
|
||||||
BinOp::Shl | BinOp::Shr => None,
|
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +131,10 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
|
|||||||
fx.lib_call(name, param_types, vec![], &args);
|
fx.lib_call(name, param_types, vec![], &args);
|
||||||
Some(out_place.to_cvalue(fx))
|
Some(out_place.to_cvalue(fx))
|
||||||
}
|
}
|
||||||
|
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
|
||||||
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
||||||
BinOp::Div | BinOp::Rem => unreachable!(),
|
BinOp::Div | BinOp::Rem => unreachable!(),
|
||||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
|
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
|
||||||
BinOp::Shl | BinOp::Shr => unreachable!(),
|
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/num.rs
16
src/num.rs
@ -128,10 +128,11 @@ pub(crate) fn codegen_int_binop<'tcx>(
|
|||||||
let rhs = in_rhs.load_scalar(fx);
|
let rhs = in_rhs.load_scalar(fx);
|
||||||
|
|
||||||
let b = fx.bcx.ins();
|
let b = fx.bcx.ins();
|
||||||
|
// FIXME trap on overflow for the Unchecked versions
|
||||||
let val = match bin_op {
|
let val = match bin_op {
|
||||||
BinOp::Add => b.iadd(lhs, rhs),
|
BinOp::Add | BinOp::AddUnchecked => b.iadd(lhs, rhs),
|
||||||
BinOp::Sub => b.isub(lhs, rhs),
|
BinOp::Sub | BinOp::SubUnchecked => b.isub(lhs, rhs),
|
||||||
BinOp::Mul => b.imul(lhs, rhs),
|
BinOp::Mul | BinOp::MulUnchecked => b.imul(lhs, rhs),
|
||||||
BinOp::Div => {
|
BinOp::Div => {
|
||||||
if signed {
|
if signed {
|
||||||
b.sdiv(lhs, rhs)
|
b.sdiv(lhs, rhs)
|
||||||
@ -149,16 +150,19 @@ pub(crate) fn codegen_int_binop<'tcx>(
|
|||||||
BinOp::BitXor => b.bxor(lhs, rhs),
|
BinOp::BitXor => b.bxor(lhs, rhs),
|
||||||
BinOp::BitAnd => b.band(lhs, rhs),
|
BinOp::BitAnd => b.band(lhs, rhs),
|
||||||
BinOp::BitOr => b.bor(lhs, rhs),
|
BinOp::BitOr => b.bor(lhs, rhs),
|
||||||
BinOp::Shl => b.ishl(lhs, rhs),
|
BinOp::Shl | BinOp::ShlUnchecked => b.ishl(lhs, rhs),
|
||||||
BinOp::Shr => {
|
BinOp::Shr | BinOp::ShrUnchecked => {
|
||||||
if signed {
|
if signed {
|
||||||
b.sshr(lhs, rhs)
|
b.sshr(lhs, rhs)
|
||||||
} else {
|
} else {
|
||||||
b.ushr(lhs, rhs)
|
b.ushr(lhs, rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BinOp::Offset => unreachable!("Offset is not an integer operation"),
|
||||||
// Compare binops handles by `codegen_binop`.
|
// Compare binops handles by `codegen_binop`.
|
||||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty),
|
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge => {
|
||||||
|
unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CValue::by_val(val, in_lhs.layout())
|
CValue::by_val(val, in_lhs.layout())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user