-
-
Notifications
You must be signed in to change notification settings - Fork 15k
codegen_ssa: multiply scalable vec size by vscale
#158253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -476,6 +476,11 @@ pub trait BuilderMethods<'a, 'tcx>: | |
| flags: MemFlags, | ||
| ); | ||
|
|
||
| // Produce a value from calling the `vscale` intrinsic (containing the `vscale` multiplier that | ||
| // a scalable vector's element size and count can be multiplied by to get the real size of the | ||
| // vector) | ||
| fn vscale(&mut self, ty: Self::Type) -> Self::Value; | ||
|
|
||
| /// *Typed* copy for non-overlapping places. | ||
| /// | ||
| /// Has a default implementation in terms of `memcpy`, but specific backends | ||
|
|
@@ -513,6 +518,12 @@ pub trait BuilderMethods<'a, 'tcx>: | |
| temp.val.store_with_flags(self, dst.with_type(layout), flags); | ||
| } else if !layout.is_zst() { | ||
| let bytes = self.const_usize(layout.size.bytes()); | ||
| let bytes = if layout.peel_transparent_wrappers(self).ty.is_scalable_vector() { | ||
| let vscale = self.vscale(self.type_i64()); | ||
| self.mul(vscale, bytes) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pondering: should this be Also, it's really not good if everywhere looking at sizes needs to look at vscale specifically. How can it be moved into layout better?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect we'll end up refactoring |
||
| } else { | ||
| bytes | ||
| }; | ||
| self.memcpy(dst.llval, dst.align, src.llval, src.align, bytes, flags, None); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| //@ compile-flags: -Copt-level=0 -Ctarget-feature=+sve,+sve2 | ||
| //@ edition: 2021 | ||
| //@ only-aarch64 | ||
|
|
||
| #![crate_type = "lib"] | ||
| #![feature(simd_ffi)] | ||
| #![feature(stdarch_aarch64_sve)] | ||
|
|
||
| // Test that `vscale * size` is generated for `memcpy` of scalable vector types | ||
|
|
||
| use std::arch::aarch64::*; | ||
|
|
||
| #[allow(improper_ctypes)] | ||
| unsafe extern "C" { | ||
| fn svcreate2_s16_wrapper(__dst: *mut svint16x2_t, x0: *const svint16_t, x1: *const svint16_t); | ||
| fn svcreate3_s16_wrapper( | ||
| __dst: *mut svint16x3_t, | ||
| x0: *const svint16_t, | ||
| x1: *const svint16_t, | ||
| x2: *const svint16_t, | ||
| ); | ||
| fn svcreate4_s16_wrapper( | ||
| __dst: *mut svint16x4_t, | ||
| x0: *const svint16_t, | ||
| x1: *const svint16_t, | ||
| x2: *const svint16_t, | ||
| x3: *const svint16_t, | ||
| ); | ||
| } | ||
|
|
||
| pub fn foo(x0_val: svint16_t) { | ||
| unsafe { | ||
| let __pred = svptrue_b16(); | ||
|
|
||
| let mut __c_return_value = std::mem::MaybeUninit::uninit(); | ||
| svcreate2_s16_wrapper(__c_return_value.as_mut_ptr(), &raw const x0_val, &raw const x0_val); | ||
| let __c_return_value = __c_return_value.assume_init(); | ||
| // CHECK: call void @svcreate2_s16_wrapper( | ||
| // CHECK-NEXT: [[VSCALE:%.*]] = call i64 @llvm.vscale.i64() | ||
| // CHECK-NEXT: [[VSCALE_SIZE:%.*]] = mul i64 [[VSCALE]], 32 | ||
| // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64({{.*}}, {{.*}}, i64 [[VSCALE_SIZE]] | ||
|
|
||
| let eq = svcmpeq_s16( | ||
| __pred, | ||
| svget2_s16::<1>(__c_return_value), | ||
| svget2_s16::<1>(__c_return_value), | ||
| ); | ||
|
|
||
| let mut __c_return_value = std::mem::MaybeUninit::uninit(); | ||
| svcreate3_s16_wrapper( | ||
| __c_return_value.as_mut_ptr(), | ||
| &raw const x0_val, | ||
| &raw const x0_val, | ||
| &raw const x0_val, | ||
| ); | ||
| let __c_return_value = __c_return_value.assume_init(); | ||
| // CHECK: call void @svcreate3_s16_wrapper( | ||
| // CHECK-NEXT: [[VSCALE:%.*]] = call i64 @llvm.vscale.i64() | ||
| // CHECK-NEXT: [[VSCALE_SIZE:%.*]] = mul i64 [[VSCALE]], 48 | ||
| // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64({{.*}}, {{.*}}, i64 [[VSCALE_SIZE]] | ||
|
|
||
| let eq = svcmpeq_s16( | ||
| __pred, | ||
| svget3_s16::<2>(__c_return_value), | ||
| svget3_s16::<2>(__c_return_value), | ||
| ); | ||
|
|
||
| let mut __c_return_value = std::mem::MaybeUninit::uninit(); | ||
| svcreate4_s16_wrapper( | ||
| __c_return_value.as_mut_ptr(), | ||
| &raw const x0_val, | ||
| &raw const x0_val, | ||
| &raw const x0_val, | ||
| &raw const x0_val, | ||
| ); | ||
| let __c_return_value = __c_return_value.assume_init(); | ||
| // CHECK: call void @svcreate4_s16_wrapper( | ||
| // CHECK-NEXT: [[VSCALE:%.*]] = call i64 @llvm.vscale.i64() | ||
| // CHECK-NEXT: [[VSCALE_SIZE:%.*]] = mul i64 [[VSCALE]], 64 | ||
| // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64({{.*}}, {{.*}}, i64 [[VSCALE_SIZE]] | ||
|
|
||
| let eq = svcmpeq_s16( | ||
| __pred, | ||
| svget4_s16::<3>(__c_return_value), | ||
| svget4_s16::<3>(__c_return_value), | ||
| ); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.