Skip to content

Commit 16cee89

Browse files
committed
Avoid mir_operand_get_const_val hack for simd_insert and simd_extract
1 parent 1e96021 commit 16cee89

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

‎src/constant.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
490490
}
491491

492492
/// Used only for intrinsic implementations that need a compile-time constant
493+
///
494+
/// All uses of this function are a bug inside stdarch. [`eval_mir_constant`]
495+
/// should be used everywhere, but for some vendor intrinsics stdarch forgets
496+
/// to wrap the immediate argument in `const {}`, necesitating this hack to get
497+
/// the correct value at compile time instead.
493498
pub(crate)fnmir_operand_get_const_val<'tcx>(
494499
fx:&FunctionCx<'_,'_,'tcx>,
495500
operand:&Operand<'tcx>,

‎src/intrinsics/simd.rs‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
268268
let val = codegen_operand(fx,&val.node);
269269

270270
// FIXME validate
271-
let idx_const = ifletSome(idx_const) =
272-
crate::constant::mir_operand_get_const_val(fx,&idx.node)
273-
{
274-
idx_const
271+
let idx_const = ifletSome(idx_const) = idx.node.constant(){
272+
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
275273
}else{
276274
fx.tcx.dcx().span_fatal(span,"Index argument for `simd_insert` is not a constant");
277275
};
@@ -304,22 +302,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
304302
return;
305303
}
306304

307-
let idx_const = ifletSome(idx_const) =
308-
crate::constant::mir_operand_get_const_val(fx,&idx.node)
309-
{
310-
idx_const
305+
let idx_const = ifletSome(idx_const) = idx.node.constant(){
306+
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
311307
}else{
312-
fx.tcx.dcx().span_warn(span,"Index argument for `simd_extract` is not a constant");
313-
let trap_block = fx.bcx.create_block();
314-
let true_ = fx.bcx.ins().iconst(types::I8,1);
315-
let ret_block = fx.get_block(target);
316-
fx.bcx.ins().brif(true_, trap_block,&[], ret_block,&[]);
317-
fx.bcx.switch_to_block(trap_block);
318-
crate::trap::trap_unimplemented(
319-
fx,
320-
"Index argument for `simd_extract` is not a constant",
321-
);
322-
return;
308+
fx.tcx
309+
.dcx()
310+
.span_fatal(span,"Index argument for `simd_extract` is not a constant");
323311
};
324312

325313
let idx = idx_const.to_u32();

0 commit comments

Comments
 (0)