Skip to content

Commit 660305d

Browse files
committed
Fix simd_gather
1 parent a29fd9c commit 660305d

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/builder.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,18 +1923,35 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19231923
self.int_type
19241924
};
19251925

1926-
let vector_type =
1927-
mask.get_type().dyncast_vector().expect("simd_shuffle mask should be of vector type");
1928-
let mask_num_units = vector_type.get_num_units();
1929-
let mut mask_elements = vec![];
1930-
for i in 0..mask_num_units {
1931-
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
1932-
mask_elements.push(self.context.new_cast(
1933-
self.location,
1934-
self.extract_element(mask, index).to_rvalue(),
1935-
mask_element_type,
1936-
));
1937-
}
1926+
// NOTE: this condition is needed because we call shuffle_vector in the implementation of
1927+
// simd_gather.
1928+
let mut mask_elements = if let Some(vector_type) = mask.get_type().dyncast_vector() {
1929+
let mask_num_units = vector_type.get_num_units();
1930+
let mut mask_elements = vec![];
1931+
for i in 0..mask_num_units {
1932+
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
1933+
mask_elements.push(self.context.new_cast(
1934+
self.location,
1935+
self.extract_element(mask, index).to_rvalue(),
1936+
mask_element_type,
1937+
));
1938+
}
1939+
mask_elements
1940+
} else {
1941+
let struct_type = mask.get_type().is_struct().expect("mask should be of struct type");
1942+
let mask_num_units = struct_type.get_field_count();
1943+
let mut mask_elements = vec![];
1944+
for i in 0..mask_num_units {
1945+
let field = struct_type.get_field(i as i32);
1946+
mask_elements.push(self.context.new_cast(
1947+
self.location,
1948+
mask.access_field(self.location, field).to_rvalue(),
1949+
mask_element_type,
1950+
));
1951+
}
1952+
mask_elements
1953+
};
1954+
let mask_num_units = mask_elements.len();
19381955

19391956
// NOTE: the mask needs to be the same length as the input vectors, so add the missing
19401957
// elements in the mask if needed.

0 commit comments

Comments
 (0)