On Tue, Aug 05, 2025 at 12:04:56PM GMT, Jakub Jelinek wrote:
> On Sat, Aug 02, 2025 at 05:14:22PM +0800, Yang Yujie wrote:
> >  tree
> > -bitint_large_huge::limb_access (tree type, tree var, tree idx, bool 
> > write_p)
> > +bitint_large_huge::limb_access (tree type, tree var, tree idx, bool 
> > write_p,
> > +                           bool abi_load_p)
> >  {
> >    tree atype = (tree_fits_uhwi_p (idx)
> >             ? limb_access_type (type, idx) : m_limb_type);
> > -  tree ltype = m_limb_type;
> > +
> > +  tree ltype = (bitint_extended && abi_load_p) ? atype : m_limb_type;
> > +
> >    addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (var));
> >    if (as != TYPE_ADDR_SPACE (ltype))
> >      ltype = build_qualified_type (ltype, TYPE_QUALS (ltype)
> > @@ -651,12 +654,21 @@ bitint_large_huge::limb_access (tree type, tree var, 
> > tree idx, bool write_p)
> >     {
> >       unsigned HOST_WIDE_INT nelts
> >         = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var))), limb_prec);
> > -     tree atype = build_array_type_nelts (ltype, nelts);
> > +
> > +     /* 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);
> >      }
> > -  if (!write_p && !useless_type_conversion_p (atype, m_limb_type))
> > +  if (!write_p && !useless_type_conversion_p (atype, ltype))
> 
> This part is not correct.  For non-generic address space this
> will be always non-useless conversion.  If you want to do nothing
> for the bitint_extended && abi_load_p case, I'd write it as
>   if (!write_p
>       && !(bitint_extended && abi_load_p)
>       && !useless_type_conversion_p (atype, m_limb_type))
> 
>       Jakub

I am not familiar with the non-generic address spaces, but I assume it would be
OK to have a final cast on the result as long as it is not a truncation,
which cannot be optimized away later.

Also, this cast seems to serve a purpose if loading from these address
spaces is not a no-op (not sure about this too).

Yujie

Reply via email to