]> git.ipfire.org Git - thirdparty/gcc.git/commit
ext-dce: Fix subreg_lsb is_constant assumption
authorRichard Sandiford <richard.sandiford@arm.com>
Mon, 21 Jul 2025 14:41:00 +0000 (15:41 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Mon, 21 Jul 2025 14:41:00 +0000 (15:41 +0100)
commit9e8af6864b9fdfae109248a4d162bba9cc008b60
tree204d7f10aeadd32b92496eec22a7a3cf42b1cf9e
parent2363ea8392b603bb5fd196a220a76a510e1115f5
ext-dce: Fix subreg_lsb is_constant assumption

ext-dce had:

  if (SUBREG_P (dst) && SUBREG_BYTE (dst).is_constant ())
    {
      bit = subreg_lsb (dst).to_constant ();
      if (bit >= HOST_BITS_PER_WIDE_INT)
bit = HOST_BITS_PER_WIDE_INT - 1;
      dst = SUBREG_REG (dst);

But a constant SUBREG_BYTE doesn't guarantee a constant subreg_lsb.
If the SUBREG_REG is a pair of N-bit registers on a big-endian target,
the most significant end has a SUBREG_BYTE of 0 but a subreg_lsb of N.
This N would then be non-constant for variable-length registers.

The patch fixes gcc.dg/torture/pr120276.c and other failures on
aarch64_be-elf.

gcc/
* ext-dce.cc (ext_dce_process_uses): Apply is_constant directly
to the subreg_lsb.

(cherry picked from commit bf3037e923e9f91d93ab64bdf73a37f64f659fb9)
gcc/ext-dce.cc