===================================================================
@@ -1129,17 +1129,7 @@ replace_reg_with_saved_mem (rtx *loc,
{
/* This is gen_lowpart_if_possible(), but without validating
the newly-formed address. */
- int offset = 0;
-
- if (WORDS_BIG_ENDIAN)
- offset = (MAX (GET_MODE_SIZE (GET_MODE (mem)), UNITS_PER_WORD)
- - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
- if (BYTES_BIG_ENDIAN)
- /* Adjust the address so that the address-after-the-data is
- unchanged. */
- offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
- - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (mem))));
-
+ HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (mem));
mem = adjust_address_nv (mem, mode, offset);
}
}
===================================================================
@@ -11458,8 +11458,6 @@ gen_lowpart_for_combine (machine_mode om
if (MEM_P (x))
{
- int offset = 0;
-
/* Refuse to work on a volatile memory ref or one with a mode-dependent
address. */
if (MEM_VOLATILE_P (x)
@@ -11472,14 +11470,7 @@ gen_lowpart_for_combine (machine_mode om
if (paradoxical_subreg_p (omode, imode))
return gen_rtx_SUBREG (omode, x, 0);
- if (WORDS_BIG_ENDIAN)
- offset = MAX (isize, UNITS_PER_WORD) - MAX (osize, UNITS_PER_WORD);
-
- /* Adjust the address so that the address-after-the-data is
- unchanged. */
- if (BYTES_BIG_ENDIAN)
- offset -= MIN (UNITS_PER_WORD, osize) - MIN (UNITS_PER_WORD, isize);
-
+ HOST_WIDE_INT offset = byte_lowpart_offset (omode, imode);
return adjust_address_nv (x, omode, offset);
}
===================================================================
@@ -19064,12 +19064,11 @@ rtl_for_decl_location (tree decl)
else if (VAR_P (decl)
&& rtl
&& MEM_P (rtl)
- && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
- && BYTES_BIG_ENDIAN)
+ && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl)))
{
machine_mode addr_mode = get_address_mode (rtl);
- int rsize = GET_MODE_SIZE (GET_MODE (rtl));
- int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
+ HOST_WIDE_INT offset = byte_lowpart_offset (TYPE_MODE (TREE_TYPE (decl)),
+ GET_MODE (rtl));
/* If a variable is declared "register" yet is smaller than
a register, then if we store the variable to memory, it
@@ -19077,10 +19076,9 @@ rtl_for_decl_location (tree decl)
fact we are not. We need to adjust the offset of the
storage location to reflect the actual value's bytes,
else gdb will not be able to display it. */
- if (rsize > dsize)
+ if (offset != 0)
rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
- plus_constant (addr_mode, XEXP (rtl, 0),
- rsize - dsize));
+ plus_constant (addr_mode, XEXP (rtl, 0), offset));
}
/* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
===================================================================
@@ -3205,14 +3205,7 @@ alter_subreg (rtx *xp, bool final_p)
/* For paradoxical subregs on big-endian machines, SUBREG_BYTE
contains 0 instead of the proper offset. See simplify_subreg. */
if (paradoxical_subreg_p (x))
- {
- int difference = GET_MODE_SIZE (GET_MODE (y))
- - GET_MODE_SIZE (GET_MODE (x));
- if (WORDS_BIG_ENDIAN)
- offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
- if (BYTES_BIG_ENDIAN)
- offset += difference % UNITS_PER_WORD;
- }
+ offset = byte_lowpart_offset (GET_MODE (x), GET_MODE (y));
if (final_p)
*xp = adjust_address (y, GET_MODE (x), offset);
===================================================================
@@ -58,8 +58,6 @@ gen_lowpart_general (machine_mode mode,
}
else
{
- int offset = 0;
-
/* The only additional case we can do is MEM. */
gcc_assert (MEM_P (x));
@@ -70,16 +68,7 @@ gen_lowpart_general (machine_mode mode,
&& !reload_completed)
return gen_lowpart_general (mode, force_reg (GET_MODE (x), x));
- if (WORDS_BIG_ENDIAN)
- offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
- - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
-
- if (BYTES_BIG_ENDIAN)
- /* Adjust the address so that the address-after-the-data
- is unchanged. */
- offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
- - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
-
+ HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x));
return adjust_address (x, mode, offset);
}
}
@@ -132,19 +121,8 @@ gen_lowpart_if_possible (machine_mode mo
else if (MEM_P (x))
{
/* This is the only other case we handle. */
- int offset = 0;
- rtx new_rtx;
-
- if (WORDS_BIG_ENDIAN)
- offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
- - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
- if (BYTES_BIG_ENDIAN)
- /* Adjust the address so that the address-after-the-data is
- unchanged. */
- offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
- - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
-
- new_rtx = adjust_address_nv (x, mode, offset);
+ HOST_WIDE_INT offset = byte_lowpart_offset (mode, GET_MODE (x));
+ rtx new_rtx = adjust_address_nv (x, mode, offset);
if (! memory_address_addr_space_p (mode, XEXP (new_rtx, 0),
MEM_ADDR_SPACE (x)))
return 0;