Skip to content

Commit f4f35e5

Browse files
committed
abi layout: change SIMD abi to not overalign vectors
1 parent 7c017c3 commit f4f35e5

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use itertools::Itertools;
88
use rspirv::spirv::{Dim, ImageFormat, StorageClass, Word};
99
use rustc_abi::ExternAbi as Abi;
1010
use rustc_abi::{
11-
Align, BackendRepr, FieldIdx, FieldsShape, HasDataLayout as _, LayoutData, Primitive,
12-
ReprFlags, ReprOptions, Scalar, Size, TagEncoding, VariantIdx, Variants,
11+
Align, BackendRepr, FieldIdx, FieldsShape, LayoutData, Primitive, ReprFlags, ReprOptions,
12+
Scalar, Size, TagEncoding, VariantIdx, Variants,
1313
};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_errors::ErrorGuaranteed;
@@ -205,10 +205,9 @@ pub(crate) fn provide(providers: &mut Providers) {
205205
tcx,
206206
key.typing_env.with_post_analysis_normalized(tcx),
207207
);
208-
let dl = cx.data_layout();
209208

210209
// Compute the ABI of the element type:
211-
let e_ly = cx.layout_of(e_ty)?;
210+
let e_ly: TyAndLayout<'_> = cx.layout_of(e_ty)?;
212211
let BackendRepr::Scalar(e_repr) = e_ly.backend_repr else {
213212
// This error isn't caught in typeck, e.g., if
214213
// the element type of the vector is generic.
@@ -223,8 +222,8 @@ pub(crate) fn provide(providers: &mut Providers) {
223222
};
224223

225224
// Compute the size and alignment of the vector:
226-
let size = e_ly.size.checked_mul(e_len, dl).unwrap();
227-
let align = dl.llvmlike_vector_align(size);
225+
let size = e_ly.size.checked_mul(e_len, &cx).unwrap();
226+
let align = e_ly.align;
228227
let size = size.align_to(align.abi);
229228

230229
let layout = tcx.mk_layout(LayoutData {

crates/rustc_codegen_spirv/src/spirv_type.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ impl SpirvType<'_> {
280280
Self::Bool => Size::from_bytes(1),
281281
Self::Integer(width, _) | Self::Float(width) => Size::from_bits(width),
282282
Self::Adt { size, .. } => size?,
283-
Self::Vector { element, count } => {
284-
cx.lookup_type(element).sizeof(cx)? * count.next_power_of_two() as u64
285-
}
283+
Self::Vector { element, count } => cx.lookup_type(element).sizeof(cx)? * count as u64,
286284
Self::Matrix { element, count } => cx.lookup_type(element).sizeof(cx)? * count as u64,
287285
Self::Array { element, count } => {
288286
cx.lookup_type(element).sizeof(cx)?
@@ -311,14 +309,8 @@ impl SpirvType<'_> {
311309
Self::Bool => Align::from_bytes(1).unwrap(),
312310
Self::Integer(width, _) | Self::Float(width) => Align::from_bits(width as u64).unwrap(),
313311
Self::Adt { align, .. } => align,
314-
// Vectors have size==align
315-
Self::Vector { .. } => Align::from_bytes(
316-
self.sizeof(cx)
317-
.expect("alignof: Vectors must be sized")
318-
.bytes(),
319-
)
320-
.expect("alignof: Vectors must have power-of-2 size"),
321-
Self::Array { element, .. }
312+
Self::Vector { element, .. }
313+
| Self::Array { element, .. }
322314
| Self::RuntimeArray { element }
323315
| Self::Matrix { element, .. } => cx.lookup_type(element).alignof(cx),
324316
Self::Pointer { .. } => cx.tcx.data_layout.pointer_align.abi,

0 commit comments

Comments
 (0)