diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-23 20:17:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 20:17:51 +0200 |
| commit | 6a2ad5510824ae3268bceb31661f3f7e21c88801 (patch) | |
| tree | 150b6464cd36599942f75fb83967e457c6356165 | |
| parent | e654877b2fe85e168513add63552149fdddc2ff7 (diff) | |
| parent | d5273fff484b0a88f599636b15b4efe2266749c3 (diff) | |
| download | rust-6a2ad5510824ae3268bceb31661f3f7e21c88801.tar.gz rust-6a2ad5510824ae3268bceb31661f3f7e21c88801.zip | |
Rollup merge of #124003 - WaffleLapkin:dellvmization, r=scottmcm,RalfJung,antoyo
Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics) This implements https://github.com/rust-lang/compiler-team/issues/693 minus what was implemented in #123226. Note: I decided to _not_ change `shl`/... builder methods, as it just doesn't seem worth it. r? ``@scottmcm``
| -rw-r--r-- | example/example.rs | 2 | ||||
| -rw-r--r-- | example/mini_core.rs | 2 | ||||
| -rw-r--r-- | src/intrinsics/mod.rs | 10 |
3 files changed, 9 insertions, 5 deletions
diff --git a/example/example.rs b/example/example.rs index 885e55bc764..1ef2aa5dd8e 100644 --- a/example/example.rs +++ b/example/example.rs @@ -149,7 +149,7 @@ pub fn array_as_slice(arr: &[u8; 3]) -> &[u8] { arr } -pub unsafe fn use_ctlz_nonzero(a: u16) -> u16 { +pub unsafe fn use_ctlz_nonzero(a: u16) -> u32 { intrinsics::ctlz_nonzero(a) } diff --git a/example/mini_core.rs b/example/mini_core.rs index e45c16ee280..5e535ff62e1 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -627,7 +627,7 @@ pub mod intrinsics { pub fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize; pub fn copy<T>(src: *const T, dst: *mut T, count: usize); pub fn transmute<T, U>(e: T) -> U; - pub fn ctlz_nonzero<T>(x: T) -> T; + pub fn ctlz_nonzero<T>(x: T) -> u32; #[rustc_safe_intrinsic] pub fn needs_drop<T: ?::Sized>() -> bool; #[rustc_safe_intrinsic] diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 0b213ff8269..79a90507fa2 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -26,6 +26,7 @@ use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Symbol}; pub(crate) use self::llvm::codegen_llvm_intrinsic_call; +use crate::cast::clif_intcast; use crate::prelude::*; fn bug_on_incorrect_arg_count(intrinsic: impl std::fmt::Display) -> ! { @@ -627,7 +628,8 @@ fn codegen_regular_intrinsic_call<'tcx>( // FIXME trap on `ctlz_nonzero` with zero arg. let res = fx.bcx.ins().clz(val); - let res = CValue::by_val(res, arg.layout()); + let res = clif_intcast(fx, res, types::I32, false); + let res = CValue::by_val(res, ret.layout()); ret.write_cvalue(fx, res); } sym::cttz | sym::cttz_nonzero => { @@ -636,7 +638,8 @@ fn codegen_regular_intrinsic_call<'tcx>( // FIXME trap on `cttz_nonzero` with zero arg. let res = fx.bcx.ins().ctz(val); - let res = CValue::by_val(res, arg.layout()); + let res = clif_intcast(fx, res, types::I32, false); + let res = CValue::by_val(res, ret.layout()); ret.write_cvalue(fx, res); } sym::ctpop => { @@ -644,7 +647,8 @@ fn codegen_regular_intrinsic_call<'tcx>( let val = arg.load_scalar(fx); let res = fx.bcx.ins().popcnt(val); - let res = CValue::by_val(res, arg.layout()); + let res = clif_intcast(fx, res, types::I32, false); + let res = CValue::by_val(res, ret.layout()); ret.write_cvalue(fx, res); } sym::bitreverse => { |
