Hi Jakub,

Gentle ping :).

On Tue, 2025-08-19 at 19:37 +0800, Yang Yujie wrote:
> This patch fixes regressions of the gcc.dg/torture/bitint-* tests
> caused by r16-3036-ga76a032354ee48 with --enable-checking=all.
> 
> The errors are similar to the following:
> 
> ../../gcc/testsuite/gcc.dg/torture/bitint-14.c:54:1: error: type mismatch in 
> 'array_ref'
> <unnamed-signed:63>
> 
> unsigned long
> 
> _42 = VIEW_CONVERT_EXPR<unsigned long[10]>(r575[i_10])[8];
> during GIMPLE pass: bitintlower0
> ../../gcc/testsuite/gcc.dg/torture/bitint-14.c:54:1: internal compiler error: 
> verify_gimple failed
> 
> Sorry about this.
> 
>       PR target/117599
> 
> gcc/ChangeLog:
> 
>       * gimple-lower-bitint.cc (bitint_large_huge::limb_access):
>       Avoid emitting ARRAY_REF with the wrong element type.
> ---
>  gcc/gimple-lower-bitint.cc | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 
> diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
> index 1e434ce7a0c..e7ea4984db2 100644
> --- a/gcc/gimple-lower-bitint.cc
> +++ b/gcc/gimple-lower-bitint.cc
> @@ -651,25 +651,37 @@ bitint_large_huge::limb_access (tree type, tree var, 
> tree idx, bool write_p,
>    else
>      {
>        var = unshare_expr (var);
> +
> +      /* Build m_limb_type from the right address space.  */
> +      tree limb_type_a = m_limb_type;
> +      if (as != TYPE_ADDR_SPACE (m_limb_type))
> +     limb_type_a = build_qualified_type (m_limb_type,
> +                                         TYPE_QUALS (m_limb_type)
> +                                         | ENCODE_QUAL_ADDR_SPACE (as));
> +
>        if (TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE
> -       || !useless_type_conversion_p (m_limb_type,
> +       || !useless_type_conversion_p (limb_type_a,
>                                        TREE_TYPE (TREE_TYPE (var))))
>       {
>         unsigned HOST_WIDE_INT nelts
>           = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var))), limb_prec);
>  
> -       /* Build the array type with m_limb_type from the right address
> -          space.  */
> -       tree limb_type_a = m_limb_type;
> -       if (as != TYPE_ADDR_SPACE (m_limb_type))
> -         limb_type_a = build_qualified_type (m_limb_type,
> -                                             TYPE_QUALS (m_limb_type)
> -                                             | ENCODE_QUAL_ADDR_SPACE (as));
> -
>         tree atype = build_array_type_nelts (limb_type_a, nelts);
>         var = build1 (VIEW_CONVERT_EXPR, atype, var);
>       }
> -      ret = build4 (ARRAY_REF, ltype, var, idx, NULL_TREE, NULL_TREE);
> +
> +      ret = build4 (ARRAY_REF, limb_type_a, var, idx, NULL_TREE, NULL_TREE);
> +
> +      if (!useless_type_conversion_p (ltype, limb_type_a))
> +     {
> +       tree base = make_ssa_name (build_pointer_type (limb_type_a));
> +       gimple *g = gimple_build_assign (base, build_fold_addr_expr (ret));
> +       insert_before (g);
> +
> +       tree ptrtype = build_pointer_type (ltype);
> +       ret = build2 (MEM_REF, ltype, add_cast (ptrtype, base),
> +                     build_zero_cst (ptrtype));
> +     }
>      }
>    if (!write_p && !useless_type_conversion_p (atype, ltype))
>      {

-- 
Xi Ruoyao <[email protected]>

Reply via email to