Skip to content

Commit ec1545d

Browse files
committed
simd_shuffle: require index argument to be a vector
1 parent 0f1df89 commit ec1545d

File tree

2 files changed

+19
-45
lines changed

2 files changed

+19
-45
lines changed

src/builder.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,33 +1939,18 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
19391939
self.int_type
19401940
};
19411941

1942-
let mut mask_elements = if let Some(vector_type) = mask.get_type().dyncast_vector() {
1943-
let mask_num_units = vector_type.get_num_units();
1944-
let mut mask_elements = vec![];
1945-
for i in 0..mask_num_units {
1946-
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
1947-
mask_elements.push(self.context.new_cast(
1948-
self.location,
1949-
self.extract_element(mask, index).to_rvalue(),
1950-
mask_element_type,
1951-
));
1952-
}
1953-
mask_elements
1954-
} else {
1955-
let struct_type = mask.get_type().is_struct().expect("mask should be of struct type");
1956-
let mask_num_units = struct_type.get_field_count();
1957-
let mut mask_elements = vec![];
1958-
for i in 0..mask_num_units {
1959-
let field = struct_type.get_field(i as i32);
1960-
mask_elements.push(self.context.new_cast(
1961-
self.location,
1962-
mask.access_field(self.location, field).to_rvalue(),
1963-
mask_element_type,
1964-
));
1965-
}
1966-
mask_elements
1967-
};
1968-
let mask_num_units = mask_elements.len();
1942+
let vector_type =
1943+
mask.get_type().dyncast_vector().expect("simd_shuffle mask should be of vector type");
1944+
let mask_num_units = vector_type.get_num_units();
1945+
let mut mask_elements = vec![];
1946+
for i in 0..mask_num_units {
1947+
let index = self.context.new_rvalue_from_long(self.cx.type_u32(), i as _);
1948+
mask_elements.push(self.context.new_cast(
1949+
self.location,
1950+
self.extract_element(mask, index).to_rvalue(),
1951+
mask_element_type,
1952+
));
1953+
}
19691954

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

src/intrinsic/simd.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
1414
#[cfg(feature = "master")]
1515
use rustc_hir as hir;
1616
use rustc_middle::mir::BinOp;
17-
use rustc_middle::span_bug;
1817
use rustc_middle::ty::layout::HasTyCtxt;
1918
use rustc_middle::ty::{self, Ty};
2019
use rustc_span::{sym, Span, Symbol};
@@ -353,24 +352,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
353352
}
354353

355354
if name == sym::simd_shuffle {
356-
// Make sure this is actually an array or SIMD vector, since typeck only checks the length-suffixed
357-
// version of this intrinsic.
355+
// Make sure this is actually a SIMD vector.
358356
let idx_ty = args[2].layout.ty;
359-
let n: u64 = match idx_ty.kind() {
360-
ty::Array(ty, len) if matches!(*ty.kind(), ty::Uint(ty::UintTy::U32)) => {
361-
len.try_eval_target_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(
362-
|| span_bug!(span, "could not evaluate shuffle index array length"),
363-
)
364-
}
365-
_ if idx_ty.is_simd()
366-
&& matches!(
367-
idx_ty.simd_size_and_type(bx.cx.tcx).1.kind(),
368-
ty::Uint(ty::UintTy::U32)
369-
) =>
370-
{
371-
idx_ty.simd_size_and_type(bx.cx.tcx).0
372-
}
373-
_ => return_error!(InvalidMonomorphization::SimdShuffle { span, name, ty: idx_ty }),
357+
let n: u64 = if idx_ty.is_simd()
358+
&& matches!(idx_ty.simd_size_and_type(bx.cx.tcx).1.kind(), ty::Uint(ty::UintTy::U32))
359+
{
360+
idx_ty.simd_size_and_type(bx.cx.tcx).0
361+
} else {
362+
return_error!(InvalidMonomorphization::SimdShuffle { span, name, ty: idx_ty })
374363
};
375364
require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });
376365

0 commit comments

Comments
 (0)