@@ -935,9 +935,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
935935 }
936936
937937 macro_rules! require_simd {
938- ( $ty: expr, $diag: expr) => {
939- require!( $ty. is_simd( ) , $diag)
940- } ;
938+ ( $ty: expr, $variant: ident) => { {
939+ require!( $ty. is_simd( ) , InvalidMonomorphization :: $variant { span, name, ty: $ty } ) ;
940+ $ty. simd_size_and_type( bx. tcx( ) )
941+ } } ;
941942 }
942943
943944 let tcx = bx. tcx ( ) ;
@@ -946,12 +947,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
946947 let arg_tys = sig. inputs ( ) ;
947948
948949 if name == sym:: simd_select_bitmask {
949- require_simd ! (
950- arg_tys[ 1 ] ,
951- InvalidMonomorphization :: SimdArgument { span, name, ty: arg_tys[ 1 ] }
952- ) ;
953-
954- let ( len, _) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
950+ let ( len, _) = require_simd ! ( arg_tys[ 1 ] , SimdArgument ) ;
955951
956952 let expected_int_bits = ( len. max ( 8 ) - 1 ) . next_power_of_two ( ) ;
957953 let expected_bytes = len / 8 + ( ( len % 8 > 0 ) as u64 ) ;
@@ -988,7 +984,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
988984 }
989985
990986 // every intrinsic below takes a SIMD vector as its first argument
991- require_simd ! ( arg_tys [ 0 ] , InvalidMonomorphization :: SimdInput { span , name , ty : arg_tys[ 0 ] } ) ;
987+ let ( in_len , in_elem ) = require_simd ! ( arg_tys[ 0 ] , SimdInput ) ;
992988 let in_ty = arg_tys[ 0 ] ;
993989
994990 let comparison = match name {
@@ -1001,11 +997,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1001997 _ => None ,
1002998 } ;
1003999
1004- let ( in_len, in_elem) = arg_tys[ 0 ] . simd_size_and_type ( bx. tcx ( ) ) ;
10051000 if let Some ( cmp_op) = comparison {
1006- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1007-
1008- let ( out_len, out_ty) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1001+ let ( out_len, out_ty) = require_simd ! ( ret_ty, SimdReturn ) ;
10091002
10101003 require ! (
10111004 in_len == out_len,
@@ -1041,8 +1034,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
10411034 . unwrap_branch ( ) ;
10421035 let n = idx. len ( ) as u64 ;
10431036
1044- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1045- let ( out_len, out_ty) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1037+ let ( out_len, out_ty) = require_simd ! ( ret_ty, SimdReturn ) ;
10461038 require ! (
10471039 out_len == n,
10481040 InvalidMonomorphization :: ReturnLength { span, name, in_len: n, ret_ty, out_len }
@@ -1099,8 +1091,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
10991091 } ) ,
11001092 } ;
11011093
1102- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1103- let ( out_len, out_ty) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1094+ let ( out_len, out_ty) = require_simd ! ( ret_ty, SimdReturn ) ;
11041095 require ! (
11051096 out_len == n,
11061097 InvalidMonomorphization :: ReturnLength { span, name, in_len: n, ret_ty, out_len }
@@ -1179,11 +1170,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11791170 if name == sym:: simd_select {
11801171 let m_elem_ty = in_elem;
11811172 let m_len = in_len;
1182- require_simd ! (
1183- arg_tys[ 1 ] ,
1184- InvalidMonomorphization :: SimdArgument { span, name, ty: arg_tys[ 1 ] }
1185- ) ;
1186- let ( v_len, _) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1173+ let ( v_len, _) = require_simd ! ( arg_tys[ 1 ] , SimdArgument ) ;
11871174 require ! (
11881175 m_len == v_len,
11891176 InvalidMonomorphization :: MismatchedLengths { span, name, m_len, v_len }
@@ -1401,20 +1388,16 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14011388 // * M: any integer width is supported, will be truncated to i1
14021389
14031390 // All types must be simd vector types
1404- require_simd ! ( in_ty, InvalidMonomorphization :: SimdFirst { span, name, ty: in_ty } ) ;
1405- require_simd ! (
1406- arg_tys[ 1 ] ,
1407- InvalidMonomorphization :: SimdSecond { span, name, ty: arg_tys[ 1 ] }
1408- ) ;
1409- require_simd ! (
1410- arg_tys[ 2 ] ,
1411- InvalidMonomorphization :: SimdThird { span, name, ty: arg_tys[ 2 ] }
1412- ) ;
1413- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1391+
1392+ // The second argument must be a simd vector with an element type that's a pointer
1393+ // to the element type of the first argument
1394+ let ( _, element_ty0) = require_simd ! ( in_ty, SimdFirst ) ;
1395+ let ( out_len, element_ty1) = require_simd ! ( arg_tys[ 1 ] , SimdSecond ) ;
1396+ // The element type of the third argument must be a signed integer type of any width:
1397+ let ( out_len2, element_ty2) = require_simd ! ( arg_tys[ 2 ] , SimdThird ) ;
1398+ require_simd ! ( ret_ty, SimdReturn ) ;
14141399
14151400 // Of the same length:
1416- let ( out_len, _) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1417- let ( out_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
14181401 require ! (
14191402 in_len == out_len,
14201403 InvalidMonomorphization :: SecondArgumentLength {
@@ -1444,11 +1427,6 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14441427 InvalidMonomorphization :: ExpectedReturnType { span, name, in_ty, ret_ty }
14451428 ) ;
14461429
1447- // The second argument must be a simd vector with an element type that's a pointer
1448- // to the element type of the first argument
1449- let ( _, element_ty0) = arg_tys[ 0 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1450- let ( _, element_ty1) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1451-
14521430 require ! (
14531431 matches!(
14541432 element_ty1. kind( ) ,
@@ -1465,20 +1443,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14651443 }
14661444 ) ;
14671445
1468- // The element type of the third argument must be a signed integer type of any width:
1469- let ( _, element_ty2) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
14701446 match element_ty2. kind ( ) {
14711447 ty:: Int ( _) => ( ) ,
14721448 _ => {
1473- require ! (
1474- false ,
1475- InvalidMonomorphization :: ThirdArgElementType {
1476- span,
1477- name,
1478- expected_element: element_ty2,
1479- third_arg: arg_tys[ 2 ]
1480- }
1481- ) ;
1449+ return_error ! ( InvalidMonomorphization :: ThirdArgElementType {
1450+ span,
1451+ name,
1452+ expected_element: element_ty2,
1453+ third_arg: arg_tys[ 2 ]
1454+ } ) ;
14821455 }
14831456 }
14841457
@@ -1527,19 +1500,13 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15271500 // * M: any integer width is supported, will be truncated to i1
15281501
15291502 // All types must be simd vector types
1530- require_simd ! ( in_ty, InvalidMonomorphization :: SimdFirst { span, name, ty: in_ty } ) ;
1531- require_simd ! (
1532- arg_tys[ 1 ] ,
1533- InvalidMonomorphization :: SimdSecond { span, name, ty: arg_tys[ 1 ] }
1534- ) ;
1535- require_simd ! (
1536- arg_tys[ 2 ] ,
1537- InvalidMonomorphization :: SimdThird { span, name, ty: arg_tys[ 2 ] }
1538- ) ;
1503+ // The second argument must be a simd vector with an element type that's a pointer
1504+ // to the element type of the first argument
1505+ let ( _, element_ty0) = require_simd ! ( in_ty, SimdFirst ) ;
1506+ let ( element_len1, element_ty1) = require_simd ! ( arg_tys[ 1 ] , SimdSecond ) ;
1507+ let ( element_len2, element_ty2) = require_simd ! ( arg_tys[ 2 ] , SimdThird ) ;
15391508
15401509 // Of the same length:
1541- let ( element_len1, _) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1542- let ( element_len2, _) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
15431510 require ! (
15441511 in_len == element_len1,
15451512 InvalidMonomorphization :: SecondArgumentLength {
@@ -1563,12 +1530,6 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15631530 }
15641531 ) ;
15651532
1566- // The second argument must be a simd vector with an element type that's a pointer
1567- // to the element type of the first argument
1568- let ( _, element_ty0) = arg_tys[ 0 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1569- let ( _, element_ty1) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1570- let ( _, element_ty2) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1571-
15721533 require ! (
15731534 matches!(
15741535 element_ty1. kind( ) ,
@@ -1590,15 +1551,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15901551 match element_ty2. kind ( ) {
15911552 ty:: Int ( _) => ( ) ,
15921553 _ => {
1593- require ! (
1594- false ,
1595- InvalidMonomorphization :: ThirdArgElementType {
1596- span,
1597- name,
1598- expected_element: element_ty2,
1599- third_arg: arg_tys[ 2 ]
1600- }
1601- ) ;
1554+ return_error ! ( InvalidMonomorphization :: ThirdArgElementType {
1555+ span,
1556+ name,
1557+ expected_element: element_ty2,
1558+ third_arg: arg_tys[ 2 ]
1559+ } ) ;
16021560 }
16031561 }
16041562
@@ -1794,8 +1752,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
17941752 bitwise_red ! ( simd_reduce_any: vector_reduce_or, true ) ;
17951753
17961754 if name == sym:: simd_cast_ptr {
1797- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1798- let ( out_len, out_elem) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1755+ let ( out_len, out_elem) = require_simd ! ( ret_ty, SimdReturn ) ;
17991756 require ! (
18001757 in_len == out_len,
18011758 InvalidMonomorphization :: ReturnLengthInputType {
@@ -1843,8 +1800,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
18431800 }
18441801
18451802 if name == sym:: simd_expose_addr {
1846- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1847- let ( out_len, out_elem) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1803+ let ( out_len, out_elem) = require_simd ! ( ret_ty, SimdReturn ) ;
18481804 require ! (
18491805 in_len == out_len,
18501806 InvalidMonomorphization :: ReturnLengthInputType {
@@ -1872,8 +1828,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
18721828 }
18731829
18741830 if name == sym:: simd_from_exposed_addr {
1875- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1876- let ( out_len, out_elem) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1831+ let ( out_len, out_elem) = require_simd ! ( ret_ty, SimdReturn ) ;
18771832 require ! (
18781833 in_len == out_len,
18791834 InvalidMonomorphization :: ReturnLengthInputType {
@@ -1901,8 +1856,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
19011856 }
19021857
19031858 if name == sym:: simd_cast || name == sym:: simd_as {
1904- require_simd ! ( ret_ty, InvalidMonomorphization :: SimdReturn { span, name, ty: ret_ty } ) ;
1905- let ( out_len, out_elem) = ret_ty. simd_size_and_type ( bx. tcx ( ) ) ;
1859+ let ( out_len, out_elem) = require_simd ! ( ret_ty, SimdReturn ) ;
19061860 require ! (
19071861 in_len == out_len,
19081862 InvalidMonomorphization :: ReturnLengthInputType {
@@ -1989,17 +1943,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
19891943 }
19901944 _ => { /* Unsupported. Fallthrough. */ }
19911945 }
1992- require ! (
1993- false ,
1994- InvalidMonomorphization :: UnsupportedCast {
1995- span,
1996- name,
1997- in_ty,
1998- in_elem,
1999- ret_ty,
2000- out_elem
2001- }
2002- ) ;
1946+ return_error ! ( InvalidMonomorphization :: UnsupportedCast {
1947+ span,
1948+ name,
1949+ in_ty,
1950+ in_elem,
1951+ ret_ty,
1952+ out_elem
1953+ } ) ;
20031954 }
20041955 macro_rules! arith_binary {
20051956 ( $( $name: ident: $( $( $p: ident) ,* => $call: ident) ,* ; ) * ) => {
@@ -2010,8 +1961,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20101961 } ) *
20111962 _ => { } ,
20121963 }
2013- require!(
2014- false ,
1964+ return_error!(
20151965 InvalidMonomorphization :: UnsupportedOperation { span, name, in_ty, in_elem }
20161966 ) ;
20171967 } ) *
@@ -2041,8 +1991,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20411991 } ) *
20421992 _ => { } ,
20431993 }
2044- require!(
2045- false ,
1994+ return_error!(
20461995 InvalidMonomorphization :: UnsupportedOperation { span, name, in_ty, in_elem }
20471996 ) ;
20481997 } ) *
0 commit comments