diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 3552fdd183e93884dfac20e3f7b38e3fea4bab58..d7bf029973ca8c676369af030d4716b138066936 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -5305,27 +5305,21 @@ bitint_large_huge::lower_stmt (gimple *stmt) else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large && (INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || POINTER_TYPE_P (TREE_TYPE (lhs)))) + || POINTER_TYPE_P (TREE_TYPE (lhs)) + || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)) { final_cast_p = true; - if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE - && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE + if (((TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE + && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE) + || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && !POINTER_TYPE_P (TREE_TYPE (lhs)))) && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR) { /* Handle VIEW_CONVERT_EXPRs to not generally supported huge INTEGER_TYPEs like uint256_t or uint512_t. These are usually emitted from memcpy folding and backends - support moves with them but that is usually it. */ - if (TREE_CODE (rhs1) == INTEGER_CST) - { - rhs1 = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), - rhs1); - gcc_assert (rhs1 && TREE_CODE (rhs1) == INTEGER_CST); - gimple_assign_set_rhs1 (stmt, rhs1); - gimple_assign_set_rhs_code (stmt, INTEGER_CST); - update_stmt (stmt); - return; - } + support moves with them but that is usually it. + Similarly handle VCEs to vector/complex types etc. */ gcc_assert (TREE_CODE (rhs1) == SSA_NAME); if (SSA_NAME_IS_DEFAULT_DEF (rhs1) && (!SSA_NAME_VAR (rhs1) || VAR_P (SSA_NAME_VAR (rhs1)))) @@ -5376,6 +5370,18 @@ bitint_large_huge::lower_stmt (gimple *stmt) } } } + else if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large + && !INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1)) + && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR) + { + int part = var_to_partition (m_map, lhs); + gcc_assert (m_vars[part] != NULL_TREE); + lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs1), m_vars[part]); + insert_before (gimple_build_assign (lhs, rhs1)); + return; + } } if (gimple_store_p (stmt)) { @@ -5411,6 +5417,28 @@ bitint_large_huge::lower_stmt (gimple *stmt) case IMAGPART_EXPR: lower_cplxpart_stmt (lhs, g); goto handled; + case VIEW_CONVERT_EXPR: + { + tree rhs1 = gimple_assign_rhs1 (g); + rhs1 = TREE_OPERAND (rhs1, 0); + if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1))) + { + tree ltype = TREE_TYPE (rhs1); + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (lhs)); + ltype + = build_qualified_type (ltype, + TYPE_QUALS (TREE_TYPE (lhs)) + | ENCODE_QUAL_ADDR_SPACE (as)); + lhs = build1 (VIEW_CONVERT_EXPR, ltype, lhs); + gimple_assign_set_lhs (stmt, lhs); + gimple_assign_set_rhs1 (stmt, rhs1); + gimple_assign_set_rhs_code (stmt, TREE_CODE (rhs1)); + update_stmt (stmt); + return; + } + } + break; default: break; } @@ -6235,6 +6263,14 @@ gimple_lower_bitint (void) if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (s))) { tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s)); + if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR) + { + rhs1 = TREE_OPERAND (rhs1, 0); + if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && !POINTER_TYPE_P (TREE_TYPE (rhs1)) + && gimple_store_p (use_stmt)) + continue; + } if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) && ((is_gimple_assign (use_stmt) && (gimple_assign_rhs_code (use_stmt) @@ -6279,11 +6315,15 @@ gimple_lower_bitint (void) goto force_name; break; case VIEW_CONVERT_EXPR: - /* Don't merge with VIEW_CONVERT_EXPRs to - huge INTEGER_TYPEs used sometimes in memcpy - expansion. */ { tree lhs = gimple_assign_lhs (use_stmt); + /* Don't merge with VIEW_CONVERT_EXPRs to + non-integral types. */ + if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + goto force_name; + /* Don't merge with VIEW_CONVERT_EXPRs to + huge INTEGER_TYPEs used sometimes in memcpy + expansion. */ if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE && (TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)) diff --git a/gcc/testsuite/gcc.dg/bitint-93.c b/gcc/testsuite/gcc.dg/bitint-93.c new file mode 100644 index 0000000000000000000000000000000000000000..ead24daa372f87d5eb8f0fe9c3cc43cb1da65204 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-93.c @@ -0,0 +1,253 @@ +/* PR middle-end/114073 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -Wno-psabi" } */ +/* { dg-additional-options "-mavx512f" { target i?86-*-* x86_64-*-* } } */ + +typedef int V __attribute__((vector_size (sizeof (_BitInt(256))))); +typedef int W __attribute__((vector_size (sizeof (_BitInt(512))))); + +#if __BITINT_MAXWIDTH__ >= 256 && defined (__SIZEOF_INT128__) +_Complex __int128 +f1 (_BitInt(256) x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = x; + return u.y; +} + +_Complex __int128 +f2 (_BitInt(254) x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = x; + return u.y; +} + +_BitInt(256) +f3 (_Complex __int128 x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.y = x; + return u.x; +} + +_BitInt(252) +f4 (_Complex __int128 x) +{ + union U { _BitInt(252) x; _Complex __int128 y; } u; + u.y = x; + return u.x; +} + +_Complex __int128 +f5 (_BitInt(256) x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = x + 1; + return u.y; +} + +_Complex __int128 +f6 (_BitInt(254) x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = x + 1; + return u.y; +} + +_Complex __int128 +f7 (_BitInt(256) *x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.x = *x + 1; + return u.y; +} + +_Complex __int128 +f8 (_BitInt(254) *x) +{ + union U { _BitInt(254) x; _Complex __int128 y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(256) +f9 (_Complex __int128 x) +{ + union U { _BitInt(256) x; _Complex __int128 y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(252) +f10 (_Complex __int128 x) +{ + union U { _BitInt(252) x; _Complex __int128 y; } u; + u.y = x; + return u.x + 1; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 256 +V +f11 (_BitInt(256) x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = x; + return u.y; +} + +V +f12 (_BitInt(254) x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = x; + return u.y; +} + +_BitInt(256) +f13 (V x) +{ + union U { _BitInt(256) x; V y; } u; + u.y = x; + return u.x; +} + +_BitInt(252) +f14 (V x) +{ + union U { _BitInt(252) x; V y; } u; + u.y = x; + return u.x; +} + +V +f15 (_BitInt(256) x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = x + 1; + return u.y; +} + +V +f16 (_BitInt(254) x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = x + 1; + return u.y; +} + +V +f17 (_BitInt(256) *x) +{ + union U { _BitInt(256) x; V y; } u; + u.x = *x + 1; + return u.y; +} + +V +f18 (_BitInt(254) *x) +{ + union U { _BitInt(254) x; V y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(256) +f19 (V x) +{ + union U { _BitInt(256) x; V y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(252) +f20 (V x) +{ + union U { _BitInt(252) x; V y; } u; + u.y = x; + return u.x + 1; +} +#endif + +#if __BITINT_MAXWIDTH__ >= 512 +W +f21 (_BitInt(512) x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = x; + return u.y; +} + +W +f22 (_BitInt(509) x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = x; + return u.y; +} + +_BitInt(512) +f23 (W x) +{ + union U { _BitInt(512) x; W y; } u; + u.y = x; + return u.x; +} + +_BitInt(506) +f24 (W x) +{ + union U { _BitInt(506) x; W y; } u; + u.y = x; + return u.x; +} + +W +f25 (_BitInt(512) x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = x + 1; + return u.y; +} + +W +f26 (_BitInt(509) x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = x + 1; + return u.y; +} + +W +f27 (_BitInt(512) *x) +{ + union U { _BitInt(512) x; W y; } u; + u.x = *x + 1; + return u.y; +} + +W +f28 (_BitInt(509) *x) +{ + union U { _BitInt(509) x; W y; } u; + u.x = *x + 1; + return u.y; +} + +_BitInt(512) +f29 (W x) +{ + union U { _BitInt(512) x; W y; } u; + u.y = x; + return u.x + 1; +} + +_BitInt(506) +f30 (W x) +{ + union U { _BitInt(506) x; W y; } u; + u.y = x; + return u.x + 1; +} +#endif