Skip to content

Commit 34481f8

Browse files
committed
const-eval: do not call immediate_const_vector on vector of pointers
1 parent 120388c commit 34481f8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10741074
if constant_ty.is_simd() {
10751075
// However, some SIMD types do not actually use the vector ABI
10761076
// (in particular, packed SIMD types do not). Ensure we exclude those.
1077+
//
1078+
// We also have to exclude vectors of pointers because `immediate_const_vector`
1079+
// does not work for those.
10771080
let layout = bx.layout_of(constant_ty);
1078-
if let BackendRepr::SimdVector { .. } = layout.backend_repr {
1081+
let (_, element_ty) = constant_ty.simd_size_and_type(bx.tcx());
1082+
if let BackendRepr::SimdVector { .. } = layout.backend_repr
1083+
&& element_ty.is_numeric()
1084+
{
10791085
let (llval, ty) = self.immediate_const_vector(bx, constant);
10801086
return OperandRef {
10811087
val: OperandValue::Immediate(llval),

tests/ui/simd/intrinsic/splat.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ fn main() {
4141

4242
static ZERO: u8 = 0u8;
4343
let x: Simd<*const u8, 2> = simd_splat(&raw const ZERO);
44+
let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) };
4445
assert_eq!(x.into_array(), [&raw const ZERO; 2]);
45-
46-
// FIXME: this hits "could not evaluate shuffle_indices at compile time",
47-
// emitted in `immediate_const_vector`. const-eval should be able to handle
48-
// this though I think? `const { [&raw const ZERO; 2] }` appears to work.
49-
// let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) };
50-
// assert_eq!(x.into_array(), y.into_array());
46+
assert_eq!(x.into_array(), y.into_array());
5147
}
5248
}

0 commit comments

Comments
 (0)