Avoid mir_operand_get_const_val hack for simd_insert and simd_extract
This commit is contained in:
parent
1e960213e8
commit
16cee899d1
@ -490,6 +490,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
|
||||
}
|
||||
|
||||
/// Used only for intrinsic implementations that need a compile-time constant
|
||||
///
|
||||
/// All uses of this function are a bug inside stdarch. [`eval_mir_constant`]
|
||||
/// should be used everywhere, but for some vendor intrinsics stdarch forgets
|
||||
/// to wrap the immediate argument in `const {}`, necesitating this hack to get
|
||||
/// the correct value at compile time instead.
|
||||
pub(crate) fn mir_operand_get_const_val<'tcx>(
|
||||
fx: &FunctionCx<'_, '_, 'tcx>,
|
||||
operand: &Operand<'tcx>,
|
||||
|
@ -268,10 +268,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
let val = codegen_operand(fx, &val.node);
|
||||
|
||||
// FIXME validate
|
||||
let idx_const = if let Some(idx_const) =
|
||||
crate::constant::mir_operand_get_const_val(fx, &idx.node)
|
||||
{
|
||||
idx_const
|
||||
let idx_const = if let Some(idx_const) = idx.node.constant() {
|
||||
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
|
||||
} else {
|
||||
fx.tcx.dcx().span_fatal(span, "Index argument for `simd_insert` is not a constant");
|
||||
};
|
||||
@ -304,22 +302,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
return;
|
||||
}
|
||||
|
||||
let idx_const = if let Some(idx_const) =
|
||||
crate::constant::mir_operand_get_const_val(fx, &idx.node)
|
||||
{
|
||||
idx_const
|
||||
let idx_const = if let Some(idx_const) = idx.node.constant() {
|
||||
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
|
||||
} else {
|
||||
fx.tcx.dcx().span_warn(span, "Index argument for `simd_extract` is not a constant");
|
||||
let trap_block = fx.bcx.create_block();
|
||||
let true_ = fx.bcx.ins().iconst(types::I8, 1);
|
||||
let ret_block = fx.get_block(target);
|
||||
fx.bcx.ins().brif(true_, trap_block, &[], ret_block, &[]);
|
||||
fx.bcx.switch_to_block(trap_block);
|
||||
crate::trap::trap_unimplemented(
|
||||
fx,
|
||||
"Index argument for `simd_extract` is not a constant",
|
||||
);
|
||||
return;
|
||||
fx.tcx
|
||||
.dcx()
|
||||
.span_fatal(span, "Index argument for `simd_extract` is not a constant");
|
||||
};
|
||||
|
||||
let idx = idx_const.to_u32();
|
||||
|
Loading…
Reference in New Issue
Block a user