Skip to content

array memset testing #596

@brody2consult

Description

@brody2consult

UPDATED: I tried a few mutations in PR which do not trigger any CI failures on my personal fork: brody2consult#2

diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
index d86db1cbd0..c2143f4436 100644
--- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
+++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
@@ -290,22 +290,15 @@ macro_rules! simple_uni_op {
 }
 
 fn memset_fill_u16(b: u8) -> u16 {
-    b as u16 | ((b as u16) << 8)
+    0xbad_u16 | ((b as u16) << 10)
 }
 
 fn memset_fill_u32(b: u8) -> u32 {
-    b as u32 | ((b as u32) << 8) | ((b as u32) << 16) | ((b as u32) << 24)
+    0xbad_u32 | ((b as u32) << 20)
 }
 
 fn memset_fill_u64(b: u8) -> u64 {
-    b as u64
-        | ((b as u64) << 8)
-        | ((b as u64) << 16)
-        | ((b as u64) << 24)
-        | ((b as u64) << 32)
-        | ((b as u64) << 40)
-        | ((b as u64) << 48)
-        | ((b as u64) << 56)
+    0xbad_u64 | ((b as u64) << 30)
 }
 
 fn memset_dynamic_scalar(
@@ -384,9 +377,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 32 => self
                     .constant_u32(self.span(), memset_fill_u32(fill_byte))
                     .def(self),
-                64 => self
-                    .constant_u64(self.span(), memset_fill_u64(fill_byte))
-                    .def(self),
                 _ => self.fatal(format!(
                     "memset on integer width {width} not implemented yet"
                 )),
@@ -2911,7 +2901,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
         };
         let elem_ty_spv = self.lookup_type(elem_ty);
         let pat = match self.builder.lookup_const_scalar(fill_byte) {
-            Some(fill_byte) => self.memset_const_pattern(&elem_ty_spv, fill_byte as u8),
+            Some(_) => self.memset_const_pattern(&elem_ty_spv, 123),
             None => self.memset_dynamic_pattern(&elem_ty_spv, fill_byte.def(self)),
         }
         .with_type(elem_ty);

and some more that do not trigger any compiletest failures or difftest failures in my personal workarea:

diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
index d86db1cbd0..b6a867933f 100644
--- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
+++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
@@ -290,21 +290,16 @@ macro_rules! simple_uni_op {
 }
 
 fn memset_fill_u16(b: u8) -> u16 {
-    b as u16 | ((b as u16) << 8)
+    b as u16
 }
 
 fn memset_fill_u32(b: u8) -> u32 {
-    b as u32 | ((b as u32) << 8) | ((b as u32) << 16) | ((b as u32) << 24)
+    b as u32
 }
 
 fn memset_fill_u64(b: u8) -> u64 {
     b as u64
         | ((b as u64) << 8)
-        | ((b as u64) << 16)
-        | ((b as u64) << 24)
-        | ((b as u64) << 32)
-        | ((b as u64) << 40)
-        | ((b as u64) << 48)
         | ((b as u64) << 56)
 }

I discovered this while investigating possible testing for a more general solution to #594.

I suspect the test cases from PR #586 may be able to help avoid this issue if we can adapt these to test memset array fill for u64, i64, u32, etc & check the disassembly. This could give me some more confidence in case we would ever want to refactor some of this memset-related code (someday).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions