Skip to content

Commit

Permalink
Fix simd_gather
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Oct 8, 2024
1 parent f3e7c3d commit 931e6bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,18 +1926,35 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
self.int_type
};

let vector_type =
mask.get_type().dyncast_vector().expect("simd_shuffle mask should be of vector type");
let mask_num_units = vector_type.get_num_units();
let mut mask_elements = vec![];
for i in 0..mask_num_units {
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
mask_elements.push(self.context.new_cast(
self.location,
self.extract_element(mask, index).to_rvalue(),
mask_element_type,
));
}
// NOTE: this condition is needed because we call shuffle_vector in the implementation of
// simd_gather.
let mut mask_elements = if let Some(vector_type) = mask.get_type().dyncast_vector() {
let mask_num_units = vector_type.get_num_units();
let mut mask_elements = vec![];
for i in 0..mask_num_units {
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
mask_elements.push(self.context.new_cast(
self.location,
self.extract_element(mask, index).to_rvalue(),
mask_element_type,
));
}
mask_elements
} else {
let struct_type = mask.get_type().is_struct().expect("mask should be of struct type");
let mask_num_units = struct_type.get_field_count();
let mut mask_elements = vec![];
for i in 0..mask_num_units {
let field = struct_type.get_field(i as i32);
mask_elements.push(self.context.new_cast(
self.location,
mask.access_field(self.location, field).to_rvalue(),
mask_element_type,
));
}
mask_elements
};
let mask_num_units = mask_elements.len();

// NOTE: the mask needs to be the same length as the input vectors, so add the missing
// elements in the mask if needed.
Expand Down
2 changes: 2 additions & 0 deletions tests/failing-ui-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ tests/ui/codegen/equal-pointers-unequal/strict-provenance/segfault.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/zero.rs
tests/ui/sanitizer/cfi/sized-associated-ty.rs
tests/ui/sanitizer/cfi/can-reveal-opaques.rs
tests/ui/sanitizer/cfi/transparent-has-regions.rs
tests/ui/simd/simd-bitmask-notpow2.rs

0 comments on commit 931e6bd

Please sign in to comment.