]> git.ipfire.org Git - thirdparty/gcc.git/commit
emit-rtl: Tweak validate_subreg ordered_p condition [PR120447]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 4 Jun 2025 12:36:51 +0000 (13:36 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 4 Jun 2025 12:36:51 +0000 (13:36 +0100)
commit5cb46d8fff07afee5ca828303544025e4a2e17b7
tree08ed826c8da64f4c379992527a86a00eafe9457e
parent0f56d67a498fb5f6223c36589bb1f5d7ae219e45
emit-rtl: Tweak validate_subreg ordered_p condition [PR120447]

In the comment trail for PR119966, I'd said that the validate_subreg
condition:

  /* The outer size must be ordered wrt the register size, otherwise
     we wouldn't know at compile time how many registers the outer
     mode occupies.  */
  if (!ordered_p (osize, regsize))
    return false;

"is also potentially relevant" for paradoxical subregs.  But I'd
forgotten an important caveat.  If the inner size is smaller than
a register, we know that the inner value will only occupy a single
register.  Although the paradoxical subreg might extend that single
register to multiple registers by padding with undefined bits,
the register size that matters for the extension is:

   REGMODE_NATURAL_SIZE (omode)

rather than regsize's:

   REGMODE_NATURAL_SIZE (imode)

The ordered check is still relevant if the inner value spans
multiple registers.

Enabling the check above for paradoxical subregs led to an ICE in the
testcase, where we tried to generate a VNx4QI paradoxical subreg of a
QI scalar.  This was previously allowed, and AFAIK worked correctly.

The patch doesn't have the effect of relaxing the condition for
non-paradoxical subregs, since:

  known_le (osize, isize) && known_le (isize, regsize)
    => known_le (osize, regsize)
    => ordered_p (osize, regsize)

So even before the patch for PR119966, the condition only existed for
the maybe_gt (isize, regsize) case.

The term "block" used in the comment is taken from the rtl.texi
documentation of subregs.

gcc/
PR rtl-optimization/120447
* emit-rtl.cc (validate_subreg): Restrict ordered_p test
between osize and regsize to cases where the inner value
occupies multiple blocks.

gcc/testsuite/
PR rtl-optimization/120447
* gcc.dg/pr120447.c: New test.
gcc/emit-rtl.cc
gcc/testsuite/gcc.dg/pr120447.c [new file with mode: 0644]