Remove shift amount masking

Unlike the old x75 backend, the new x64 backend masks the shift amount
itself, matching the specified semantics.
This commit is contained in:
bjorn3 2021-02-21 12:03:02 +01:00
parent 4f45ea73ef
commit c5f98b586f

View File

@ -168,20 +168,12 @@ pub(crate) fn codegen_int_binop<'tcx>(
BinOp::BitXor => b.bxor(lhs, rhs),
BinOp::BitAnd => b.band(lhs, rhs),
BinOp::BitOr => b.bor(lhs, rhs),
BinOp::Shl => {
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
fx.bcx.ins().ishl(lhs, actual_shift)
}
BinOp::Shl => fx.bcx.ins().ishl(lhs, rhs),
BinOp::Shr => {
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
if signed {
fx.bcx.ins().sshr(lhs, actual_shift)
fx.bcx.ins().sshr(lhs, rhs)
} else {
fx.bcx.ins().ushr(lhs, actual_shift)
fx.bcx.ins().ushr(lhs, rhs)
}
}
// Compare binops handles by `codegen_binop`.
@ -303,10 +295,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
}
}
BinOp::Shl => {
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
let val = fx.bcx.ins().ishl(lhs, actual_shift);
let val = fx.bcx.ins().ishl(lhs, rhs);
let ty = fx.bcx.func.dfg.value_type(val);
let max_shift = i64::from(ty.bits()) - 1;
let has_overflow = fx
@ -316,13 +305,10 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
(val, has_overflow)
}
BinOp::Shr => {
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
let actual_shift = fx.bcx.ins().band_imm(rhs, i64::from(lhs_ty.bits() - 1));
let actual_shift = clif_intcast(fx, actual_shift, types::I8, false);
let val = if !signed {
fx.bcx.ins().ushr(lhs, actual_shift)
fx.bcx.ins().ushr(lhs, rhs)
} else {
fx.bcx.ins().sshr(lhs, actual_shift)
fx.bcx.ins().sshr(lhs, rhs)
};
let ty = fx.bcx.func.dfg.value_type(val);
let max_shift = i64::from(ty.bits()) - 1;