From 71f34429ac7cb65a00ec413a546ad760f6c6aa91 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Mon, 19 Jan 2026 15:53:12 +0100 Subject: [PATCH] const-eval: do not call `immediate_const_vector` on vector of pointers --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 8 +++++++- tests/codegen-llvm/simd/splat.rs | 1 + tests/ui/simd/intrinsic/splat.rs | 8 ++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 78dfecdd1818..50ca676b5d05 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -1074,8 +1074,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if constant_ty.is_simd() { // However, some SIMD types do not actually use the vector ABI // (in particular, packed SIMD types do not). Ensure we exclude those. + // + // We also have to exclude vectors of pointers because `immediate_const_vector` + // does not work for those. let layout = bx.layout_of(constant_ty); - if let BackendRepr::SimdVector { .. } = layout.backend_repr { + let (_, element_ty) = constant_ty.simd_size_and_type(bx.tcx()); + if let BackendRepr::SimdVector { .. } = layout.backend_repr + && element_ty.is_numeric() + { let (llval, ty) = self.immediate_const_vector(bx, constant); return OperandRef { val: OperandValue::Immediate(llval), diff --git a/tests/codegen-llvm/simd/splat.rs b/tests/codegen-llvm/simd/splat.rs index f3e1866fd64a..7a24162321bd 100644 --- a/tests/codegen-llvm/simd/splat.rs +++ b/tests/codegen-llvm/simd/splat.rs @@ -1,3 +1,4 @@ +//@ compile-flags: -Copt-level=3 #![crate_type = "lib"] #![no_std] #![feature(repr_simd, core_intrinsics)] diff --git a/tests/ui/simd/intrinsic/splat.rs b/tests/ui/simd/intrinsic/splat.rs index af3d2270061d..38260a124d44 100644 --- a/tests/ui/simd/intrinsic/splat.rs +++ b/tests/ui/simd/intrinsic/splat.rs @@ -41,12 +41,8 @@ fn main() { static ZERO: u8 = 0u8; let x: Simd<*const u8, 2> = simd_splat(&raw const ZERO); + let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) }; assert_eq!(x.into_array(), [&raw const ZERO; 2]); - - // FIXME: this hits "could not evaluate shuffle_indices at compile time", - // emitted in `immediate_const_vector`. const-eval should be able to handle - // this though I think? `const { [&raw const ZERO; 2] }` appears to work. - // let y: Simd<*const u8, 2> = const { simd_splat(&raw const ZERO) }; - // assert_eq!(x.into_array(), y.into_array()); + assert_eq!(x.into_array(), y.into_array()); } }