]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bitint: Fix up big-endian handling in limb_access [PR122714]
authorJakub Jelinek <jakub@redhat.com>
Thu, 27 Nov 2025 12:55:17 +0000 (13:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 27 Nov 2025 12:55:17 +0000 (13:55 +0100)
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  <jakub@redhat.com>

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

index 28802e3b4aaab8812ea85a02764b4ecdb52b09e4..f699b8ec3af9285610d37b4df99e1c68dd1ab300 100644 (file)
@@ -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);