diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs
index d53bffb3e03..068b7c1320d 100644
--- a/compiler/rustc_codegen_ssa/src/mir/block.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/block.rs
@@ -863,22 +863,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// promotes any complex rvalues to constants.
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
if let mir::Operand::Constant(constant) = arg {
- let ct = self.monomorphize(constant.literal);
- let uv = match ct {
- mir::ConstantKind::Unevaluated(uv, _) => uv.shrink(),
- other => span_bug!(constant.span, "{other:#?}"),
- };
- let c = self.cx.tcx().const_eval_resolve_for_typeck(
- ty::ParamEnv::reveal_all(),
- uv,
- Some(constant.span),
- );
- let (llval, ty) = self.simd_shuffle_indices(
- &bx,
- constant.span,
- self.monomorphize(constant.ty()),
- c,
- );
+ let (llval, ty) = self.simd_shuffle_indices(&bx, constant);
return OperandRef {
val: Immediate(llval),
layout: bx.layout_of(ty),
diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs
index a2ee9c54b16..1c5031dfc4b 100644
--- a/compiler/rustc_codegen_ssa/src/mir/constant.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs
@@ -5,7 +5,6 @@ use rustc_middle::mir;
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_middle::ty::{self, Ty};
-use rustc_span::source_map::Span;
use rustc_target::abi::Abi;
use super::FunctionCx;
@@ -59,15 +58,34 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
})
}
+ /// This is a convenience helper for `simd_shuffle_indices`. It has the precondition
+ /// that the given `constant` is an `ConstantKind::Unevaluated` and must be convertible to
+ /// a `ValTree`. If you want a more general version of this, talk to `wg-const-eval` on zulip.
+ pub fn eval_unevaluated_mir_constant_to_valtree(
+ &self,
+ constant: &mir::Constant<'tcx>,
+ ) -> Result