@@ -1421,7 +1421,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14211421 return Ok ( bx. shuffle_vector ( args[ 0 ] . immediate ( ) , args[ 1 ] . immediate ( ) , indices) ) ;
14221422 }
14231423
1424- if name == sym:: simd_insert {
1424+ if name == sym:: simd_insert || name == sym :: simd_insert_dyn {
14251425 require ! (
14261426 in_elem == arg_tys[ 2 ] ,
14271427 InvalidMonomorphization :: InsertedType {
@@ -1432,40 +1432,49 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14321432 out_ty: arg_tys[ 2 ]
14331433 }
14341434 ) ;
1435- let idx = bx
1436- . const_to_opt_u128 ( args[ 1 ] . immediate ( ) , false )
1437- . expect ( "typeck should have ensure that this is a const" ) ;
1438- if idx >= in_len. into ( ) {
1439- return_error ! ( InvalidMonomorphization :: SimdIndexOutOfBounds {
1440- span,
1441- name,
1442- arg_idx: 1 ,
1443- total_len: in_len. into( ) ,
1444- } ) ;
1445- }
1446- return Ok ( bx. insert_element (
1447- args[ 0 ] . immediate ( ) ,
1448- args[ 2 ] . immediate ( ) ,
1449- bx. const_i32 ( idx as i32 ) ,
1450- ) ) ;
1435+
1436+ let index_imm = if name == sym:: simd_insert {
1437+ let idx = bx
1438+ . const_to_opt_u128 ( args[ 1 ] . immediate ( ) , false )
1439+ . expect ( "typeck should have ensure that this is a const" ) ;
1440+ if idx >= in_len. into ( ) {
1441+ return_error ! ( InvalidMonomorphization :: SimdIndexOutOfBounds {
1442+ span,
1443+ name,
1444+ arg_idx: 1 ,
1445+ total_len: in_len. into( ) ,
1446+ } ) ;
1447+ }
1448+ bx. const_i32 ( idx as i32 )
1449+ } else {
1450+ args[ 1 ] . immediate ( )
1451+ } ;
1452+
1453+ return Ok ( bx. insert_element ( args[ 0 ] . immediate ( ) , args[ 2 ] . immediate ( ) , index_imm) ) ;
14511454 }
1452- if name == sym:: simd_extract {
1455+ if name == sym:: simd_extract || name == sym :: simd_extract_dyn {
14531456 require ! (
14541457 ret_ty == in_elem,
14551458 InvalidMonomorphization :: ReturnType { span, name, in_elem, in_ty, ret_ty }
14561459 ) ;
1457- let idx = bx
1458- . const_to_opt_u128 ( args[ 1 ] . immediate ( ) , false )
1459- . expect ( "typeck should have ensure that this is a const" ) ;
1460- if idx >= in_len. into ( ) {
1461- return_error ! ( InvalidMonomorphization :: SimdIndexOutOfBounds {
1462- span,
1463- name,
1464- arg_idx: 1 ,
1465- total_len: in_len. into( ) ,
1466- } ) ;
1467- }
1468- return Ok ( bx. extract_element ( args[ 0 ] . immediate ( ) , bx. const_i32 ( idx as i32 ) ) ) ;
1460+ let index_imm = if name == sym:: simd_extract {
1461+ let idx = bx
1462+ . const_to_opt_u128 ( args[ 1 ] . immediate ( ) , false )
1463+ . expect ( "typeck should have ensure that this is a const" ) ;
1464+ if idx >= in_len. into ( ) {
1465+ return_error ! ( InvalidMonomorphization :: SimdIndexOutOfBounds {
1466+ span,
1467+ name,
1468+ arg_idx: 1 ,
1469+ total_len: in_len. into( ) ,
1470+ } ) ;
1471+ }
1472+ bx. const_i32 ( idx as i32 )
1473+ } else {
1474+ args[ 1 ] . immediate ( )
1475+ } ;
1476+
1477+ return Ok ( bx. extract_element ( args[ 0 ] . immediate ( ) , index_imm) ) ;
14691478 }
14701479
14711480 if name == sym:: simd_select {
0 commit comments