mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Sync from rust 385fa9d845
This commit is contained in:
commit
5a9940fe3d
@ -649,8 +649,8 @@ fn codegen_stmt<'tcx>(
|
||||
| CastKind::IntToFloat
|
||||
| CastKind::FnPtrToPtr
|
||||
| CastKind::PtrToPtr
|
||||
| CastKind::PointerExposeAddress
|
||||
| CastKind::PointerFromExposedAddress,
|
||||
| CastKind::PointerExposeProvenance
|
||||
| CastKind::PointerWithExposedProvenance,
|
||||
ref operand,
|
||||
to_ty,
|
||||
) => {
|
||||
|
@ -68,7 +68,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
Some(CValue::by_val(ret_val, lhs.layout()))
|
||||
}
|
||||
}
|
||||
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 | BinOp::Cmp => None,
|
||||
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => None,
|
||||
}
|
||||
}
|
||||
@ -134,6 +134,7 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
|
||||
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
|
||||
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
||||
BinOp::Div | BinOp::Rem => unreachable!(),
|
||||
BinOp::Cmp => unreachable!(),
|
||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
|
||||
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => unreachable!(),
|
||||
}
|
||||
|
@ -1393,7 +1393,7 @@ fn llvm_add_sub<'tcx>(
|
||||
|
||||
// c + carry -> c + first intermediate carry or borrow respectively
|
||||
let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b);
|
||||
let c = int0.value_field(fx, FieldIdx::new(0));
|
||||
let c = int0.value_field(fx, FieldIdx::ZERO);
|
||||
let cb0 = int0.value_field(fx, FieldIdx::new(1)).load_scalar(fx);
|
||||
|
||||
// c + carry -> c + second intermediate carry or borrow respectively
|
||||
|
@ -965,7 +965,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
});
|
||||
}
|
||||
|
||||
sym::simd_expose_addr | sym::simd_from_exposed_addr | sym::simd_cast_ptr => {
|
||||
sym::simd_expose_provenance | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
|
||||
intrinsic_args!(fx, args => (arg); intrinsic);
|
||||
ret.write_cvalue_transmute(fx, arg);
|
||||
}
|
||||
|
24
src/num.rs
24
src/num.rs
@ -40,6 +40,22 @@ pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
|
||||
})
|
||||
}
|
||||
|
||||
fn codegen_three_way_compare<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
signed: bool,
|
||||
lhs: Value,
|
||||
rhs: Value,
|
||||
) -> CValue<'tcx> {
|
||||
// This emits `(lhs > rhs) - (lhs < rhs)`, which is cranelift's preferred form per
|
||||
// <https://github.com/bytecodealliance/wasmtime/blob/8052bb9e3b792503b225f2a5b2ba3bc023bff462/cranelift/codegen/src/prelude_opt.isle#L41-L47>
|
||||
let gt_cc = crate::num::bin_op_to_intcc(BinOp::Gt, signed).unwrap();
|
||||
let lt_cc = crate::num::bin_op_to_intcc(BinOp::Lt, signed).unwrap();
|
||||
let gt = fx.bcx.ins().icmp(gt_cc, lhs, rhs);
|
||||
let lt = fx.bcx.ins().icmp(lt_cc, lhs, rhs);
|
||||
let val = fx.bcx.ins().isub(gt, lt);
|
||||
CValue::by_val(val, fx.layout_of(fx.tcx.ty_ordering_enum(Some(fx.mir.span))))
|
||||
}
|
||||
|
||||
fn codegen_compare_bin_op<'tcx>(
|
||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||
bin_op: BinOp,
|
||||
@ -47,6 +63,10 @@ fn codegen_compare_bin_op<'tcx>(
|
||||
lhs: Value,
|
||||
rhs: Value,
|
||||
) -> CValue<'tcx> {
|
||||
if bin_op == BinOp::Cmp {
|
||||
return codegen_three_way_compare(fx, signed, lhs, rhs);
|
||||
}
|
||||
|
||||
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
|
||||
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
||||
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
|
||||
@ -59,7 +79,7 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||
in_rhs: CValue<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
match bin_op {
|
||||
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
|
||||
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt | BinOp::Cmp => {
|
||||
match in_lhs.layout().ty.kind() {
|
||||
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
|
||||
let signed = type_sign(in_lhs.layout().ty);
|
||||
@ -160,7 +180,7 @@ pub(crate) fn codegen_int_binop<'tcx>(
|
||||
}
|
||||
BinOp::Offset => unreachable!("Offset is not an integer operation"),
|
||||
// Compare binops handles by `codegen_binop`.
|
||||
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge => {
|
||||
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge | BinOp::Cmp => {
|
||||
unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty);
|
||||
}
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
|
||||
if ty.is_dyn_star() {
|
||||
let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap().ty);
|
||||
let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout);
|
||||
let ptr = dyn_star.place_field(fx, FieldIdx::new(0)).to_ptr();
|
||||
let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr();
|
||||
let vtable =
|
||||
dyn_star.place_field(fx, FieldIdx::new(1)).to_cvalue(fx).load_scalar(fx);
|
||||
break 'block (ptr, vtable);
|
||||
|
Loading…
Reference in New Issue
Block a user