https://gcc.gnu.org/g:23e1be3c9517fd0a46ec6dca5af7eae2ea977179

commit r16-5650-g23e1be3c9517fd0a46ec6dca5af7eae2ea977179
Author: Jakub Jelinek <[email protected]>
Date:   Thu Nov 27 13:55:17 2025 +0100

    bitint: Fix up big-endian handling in limb_access [PR122714]
    
    The bitint_extended changes in limb_access broke bitint_big_endian.
    As we sometimes (for bitint_extended) access the MEM_REFs using
    atype rather than m_limb_type, for big-endian we need to adjust
    the MEM_REFs offset if atype has smaller TYPE_SIZE_UNIT than m_limb_size.
    
    2025-11-27  Jakub Jelinek  <[email protected]>
    
            PR target/122714
            * gimple-lower-bitint.cc (bitint_large_huge::limb_access): Adjust
            MEM_REFs offset for bitint_big_endian if ltype doesn't have the
            same byte size as m_limb_type.

Diff:
---
 gcc/gimple-lower-bitint.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 28802e3b4aaa..f699b8ec3af9 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -630,6 +630,8 @@ bitint_large_huge::limb_access (tree type, tree var, tree 
idx, bool write_p,
                                      | ENCODE_QUAL_ADDR_SPACE (as));
       tree ptype = build_pointer_type (strip_array_types (TREE_TYPE (var)));
       unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size;
+      if (bitint_big_endian)
+       off += m_limb_size - tree_to_uhwi (TYPE_SIZE_UNIT (ltype));
       ret = build2 (MEM_REF, ltype,
                    build_fold_addr_expr (var),
                    build_int_cst (ptype, off));
@@ -641,12 +643,14 @@ bitint_large_huge::limb_access (tree type, tree var, tree 
idx, bool write_p,
       if (as != TYPE_ADDR_SPACE (ltype))
        ltype = build_qualified_type (ltype, TYPE_QUALS (ltype)
                                      | ENCODE_QUAL_ADDR_SPACE (as));
+      unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size;
+      if (bitint_big_endian)
+       off += m_limb_size - tree_to_uhwi (TYPE_SIZE_UNIT (ltype));
       ret
        = build2 (MEM_REF, ltype, unshare_expr (TREE_OPERAND (var, 0)),
                  size_binop (PLUS_EXPR, TREE_OPERAND (var, 1),
                              build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)),
-                                            tree_to_uhwi (idx)
-                                            * m_limb_size)));
+                                            off)));
       TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var);
       TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (var);
       TREE_THIS_NOTRAP (ret) = TREE_THIS_NOTRAP (var);

Reply via email to