Skip to content
/ rust Public
forked from rust-lang/rust

Commit 8fd8b2d

Browse files
committed
Only handle BinOp::Mul in codegen_i128::maybe_codegen_mul_checked
1 parent ec96e02 commit 8fd8b2d

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/codegen_i128.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ pub(crate) fn maybe_codegen<'tcx>(
6262
}
6363
}
6464

65-
pub(crate) fn maybe_codegen_checked<'tcx>(
65+
pub(crate) fn maybe_codegen_mul_checked<'tcx>(
6666
fx: &mut FunctionCx<'_, '_, 'tcx>,
67-
bin_op: BinOp,
6867
lhs: CValue<'tcx>,
6968
rhs: CValue<'tcx>,
7069
) -> Option<CValue<'tcx>> {
@@ -78,25 +77,19 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
7877

7978
let is_signed = type_sign(lhs.layout().ty);
8079

81-
match bin_op {
82-
BinOp::Add | BinOp::Sub => None,
83-
BinOp::Mul => {
84-
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
85-
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
86-
let param_types = vec![
87-
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
88-
AbiParam::new(types::I128),
89-
AbiParam::new(types::I128),
90-
];
91-
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
92-
fx.lib_call(
93-
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
94-
param_types,
95-
vec![],
96-
&args,
97-
);
98-
Some(out_place.to_cvalue(fx))
99-
}
100-
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, lhs, rhs),
101-
}
80+
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
81+
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
82+
let param_types = vec![
83+
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
84+
AbiParam::new(types::I128),
85+
AbiParam::new(types::I128),
86+
];
87+
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
88+
fx.lib_call(
89+
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
90+
param_types,
91+
vec![],
92+
&args,
93+
);
94+
Some(out_place.to_cvalue(fx))
10295
}

src/num.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
200200
let lhs = in_lhs.load_scalar(fx);
201201
let rhs = in_rhs.load_scalar(fx);
202202

203-
if let Some(res) = crate::codegen_i128::maybe_codegen_checked(fx, bin_op, in_lhs, in_rhs) {
204-
return res;
205-
}
206-
207203
let signed = type_sign(in_lhs.layout().ty);
208204

209205
let (res, has_overflow) = match bin_op {
@@ -236,6 +232,10 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
236232
(val, has_overflow)
237233
}
238234
BinOp::Mul => {
235+
if let Some(res) = crate::codegen_i128::maybe_codegen_mul_checked(fx, in_lhs, in_rhs) {
236+
return res;
237+
}
238+
239239
let ty = fx.bcx.func.dfg.value_type(lhs);
240240
match ty {
241241
types::I8 | types::I16 | types::I32 if !signed => {

0 commit comments

Comments
 (0)