https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122714

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Ah, this got broken with the loongarch bitint_extended changes.

Does the following help?  Can't test myself in the near future on big endian
easily:
2025-11-26  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.

--- gcc/gimple-lower-bitint.cc.jj       2025-09-30 13:37:48.364854566 +0200
+++ gcc/gimple-lower-bitint.cc  2025-11-26 17:03:51.815649841 +0100
@@ -630,6 +630,8 @@ bitint_large_huge::limb_access (tree typ
                                      | 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 typ
       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