Skip to content

Commit 4764b45

Browse files
Firestar99eddyb
authored andcommitted
byte_addr_buffer: fix mixed scalar and scalar pair stores
1 parent 7a72a2f commit 4764b45

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
32573257
&mut self,
32583258
callee_ty: Self::Type,
32593259
_fn_attrs: Option<&CodegenFnAttrs>,
3260-
_fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
3260+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
32613261
callee: Self::Value,
32623262
args: &[Self::Value],
32633263
funclet: Option<&Self::Funclet>,
@@ -3320,9 +3320,9 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
33203320
let libm_intrinsic =
33213321
instance_def_id.and_then(|def_id| self.libm_intrinsics.borrow().get(&def_id).copied());
33223322
let buffer_load_intrinsic = instance_def_id
3323-
.and_then(|def_id| self.buffer_load_intrinsics.borrow().get(&def_id).copied());
3323+
.is_some_and(|def_id| self.buffer_load_intrinsics.borrow().contains(&def_id));
33243324
let buffer_store_intrinsic = instance_def_id
3325-
.and_then(|def_id| self.buffer_store_intrinsics.borrow().get(&def_id).copied());
3325+
.is_some_and(|def_id| self.buffer_store_intrinsics.borrow().contains(&def_id));
33263326
let is_panic_entry_point = instance_def_id
33273327
.is_some_and(|def_id| self.panic_entry_points.borrow().contains(&def_id));
33283328
let from_trait_impl =
@@ -4111,14 +4111,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
41114111
self.abort_with_kind_and_message_debug_printf("panic", message, debug_printf_args);
41124112
return self.undef(result_type);
41134113
}
4114-
4115-
if let Some(mode) = buffer_load_intrinsic {
4116-
return self.codegen_buffer_load_intrinsic(result_type, args, mode);
4114+
if buffer_load_intrinsic {
4115+
return self.codegen_buffer_load_intrinsic(fn_abi, result_type, args);
41174116
}
4118-
4119-
if let Some(mode) = buffer_store_intrinsic {
4120-
self.codegen_buffer_store_intrinsic(args, mode);
4121-
4117+
if buffer_store_intrinsic {
4118+
self.codegen_buffer_store_intrinsic(fn_abi, args);
41224119
let void_ty = SpirvType::Void.def(rustc_span::DUMMY_SP, self);
41234120
return SpirvValue {
41244121
kind: SpirvValueKind::IllegalTypeUsed(void_ty),

crates/rustc_codegen_spirv/src/builder/byte_addressable_buffer.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use rustc_abi::{Align, Size};
99
use rustc_codegen_spirv_types::Capability;
1010
use rustc_codegen_ssa::traits::BuilderMethods;
1111
use rustc_errors::ErrorGuaranteed;
12+
use rustc_middle::ty::Ty;
1213
use rustc_span::DUMMY_SP;
13-
use rustc_target::callconv::PassMode;
14+
use rustc_target::callconv::{FnAbi, PassMode};
1415

1516
impl<'a, 'tcx> Builder<'a, 'tcx> {
1617
fn load_err(&mut self, original_type: Word, invalid_type: Word) -> SpirvValue {
@@ -181,10 +182,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
181182
/// Note: DOES NOT do bounds checking! Bounds checking is expected to be done in the caller.
182183
pub fn codegen_buffer_load_intrinsic(
183184
&mut self,
185+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
184186
result_type: Word,
185187
args: &[SpirvValue],
186-
pass_mode: &PassMode,
187188
) -> SpirvValue {
189+
let pass_mode = &fn_abi.unwrap().ret.mode;
188190
match pass_mode {
189191
PassMode::Ignore => {
190192
return SpirvValue {
@@ -364,8 +366,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
364366
}
365367

366368
/// Note: DOES NOT do bounds checking! Bounds checking is expected to be done in the caller.
367-
pub fn codegen_buffer_store_intrinsic(&mut self, args: &[SpirvValue], pass_mode: &PassMode) {
369+
pub fn codegen_buffer_store_intrinsic(
370+
&mut self,
371+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
372+
args: &[SpirvValue],
373+
) {
368374
// Signature: fn store<T>(array: &[u32], index: u32, value: T);
375+
let pass_mode = &fn_abi.unwrap().args.last().unwrap().mode;
369376
let is_pair = match pass_mode {
370377
// haha shrug
371378
PassMode::Ignore => return,

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,10 @@ impl<'tcx> CodegenCx<'tcx> {
149149
// FIXME(eddyb) should the maps exist at all, now that the `DefId` is known
150150
// at `call` time, and presumably its high-level details can be looked up?
151151
if attrs.buffer_load_intrinsic.is_some() {
152-
let mode = &fn_abi.ret.mode;
153-
self.buffer_load_intrinsics
154-
.borrow_mut()
155-
.insert(def_id, mode);
152+
self.buffer_load_intrinsics.borrow_mut().insert(def_id);
156153
}
157154
if attrs.buffer_store_intrinsic.is_some() {
158-
let mode = &fn_abi.args.last().unwrap().mode;
159-
self.buffer_store_intrinsics
160-
.borrow_mut()
161-
.insert(def_id, mode);
155+
self.buffer_store_intrinsics.borrow_mut().insert(def_id);
162156
}
163157

164158
// Check for usage of `libm` intrinsics outside of `libm` itself

crates/rustc_codegen_spirv/src/codegen_cx/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypingEnv};
3434
use rustc_session::Session;
3535
use rustc_span::symbol::Symbol;
3636
use rustc_span::{DUMMY_SP, SourceFile, Span};
37-
use rustc_target::callconv::{FnAbi, PassMode};
37+
use rustc_target::callconv::FnAbi;
3838
use rustc_target::spec::{HasTargetSpec, Target, TargetTuple};
3939
use std::cell::RefCell;
4040
use std::collections::BTreeSet;
@@ -80,9 +80,9 @@ pub struct CodegenCx<'tcx> {
8080
pub fmt_rt_arg_new_fn_ids_to_ty_and_spec: RefCell<FxHashMap<Word, (Ty<'tcx>, char)>>,
8181

8282
/// Intrinsic for loading a `<T>` from a `&[u32]`. The `PassMode` is the mode of the `<T>`.
83-
pub buffer_load_intrinsics: RefCell<FxHashMap<DefId, &'tcx PassMode>>,
83+
pub buffer_load_intrinsics: RefCell<FxHashSet<DefId>>,
8484
/// Intrinsic for storing a `<T>` into a `&[u32]`. The `PassMode` is the mode of the `<T>`.
85-
pub buffer_store_intrinsics: RefCell<FxHashMap<DefId, &'tcx PassMode>>,
85+
pub buffer_store_intrinsics: RefCell<FxHashSet<DefId>>,
8686

8787
/// Maps `DefId`s of `From::from` method implementations to their source and target types.
8888
/// Used to optimize constant conversions like `u32::from(42u8)` to avoid creating the source type.

0 commit comments

Comments
 (0)