Use correct sign extension on __powi*f2 arguments

This commit is contained in:
beetrees 2025-05-23 15:51:51 +01:00
parent 3ab6af049b
commit dcd3168c97
No known key found for this signature in database
GPG key ID: 8791BD754191EBD6
2 changed files with 30 additions and 1 deletions

View file

@ -828,3 +828,31 @@ pub(crate) fn codegen_drop<'tcx>(
}
}
}
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
let param = AbiParam::new(ty);
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size.bits() {
match (&*tcx.sess.target.arch, &*tcx.sess.target.vendor) {
("x86_64", _) | ("aarch64", "apple") => match (ty, is_signed) {
(types::I8 | types::I16, true) => param.sext(),
(types::I8 | types::I16, false) => param.uext(),
_ => param,
},
("aarch64", _) => param,
("riscv64", _) => match (ty, is_signed) {
(types::I32, _) | (_, true) => param.sext(),
_ => param.uext(),
},
("s390x", _) => {
if is_signed {
param.sext()
} else {
param.uext()
}
}
_ => unimplemented!("{:?}", tcx.sess.target.arch),
}
} else {
param
}
}

View file

@ -416,7 +416,8 @@ fn codegen_float_intrinsic_call<'tcx>(
// These intrinsics aren't supported natively by Cranelift.
// Lower them to a libcall.
sym::powif32 | sym::powif64 => {
let input_tys: Vec<_> = vec![AbiParam::new(clif_ty), AbiParam::new(types::I32)];
let input_tys: Vec<_> =
vec![AbiParam::new(clif_ty), lib_call_arg_param(fx.tcx, types::I32, true)];
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
CValue::by_val(ret_val, fx.layout_of(ty))
}