]> git.ipfire.org Git - thirdparty/gcc.git/commit
simplify-rtx: Simplify subregs of logic ops
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 29 Jul 2025 14:58:34 +0000 (15:58 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 29 Jul 2025 14:58:34 +0000 (15:58 +0100)
commit965564eafb721f8000013a3112f1bba8d8fae32b
treea7e3ff8cae6e5a34e94394c4d4d499b714f7a1e9
parentcc9c041fd1c84de8960bb2f3b30f8d53b059cba4
simplify-rtx: Simplify subregs of logic ops

This patch adds a new rule for distributing lowpart subregs through
ANDs, IORs, and XORs with a constant, in cases where one of the terms
then disappears.  For example:

  (lowart-subreg:QI (and:HI x 0x100))

simplifies to zero and

  (lowart-subreg:QI (and:HI x 0xff))

simplifies to (lowart-subreg:QI x).

This would often be handled at some point using nonzero bits.  However,
the specific case I want the optimisation for is SVE predicates,
where nonzero bit tracking isn't currently an option.  Specifically:
the predicate modes VNx8BI, VNx4BI and VNx2BI have the same size as
VNx16BI, but treat only every second, fourth, or eighth bit as
significant.  Thus if we have:

  (subreg:VNx8BI (and:VNx16BI x C))

where C is the repeating constant { 1, 0, 1, 0, ... }, then the
AND only clears bits that are made insignificant by the subreg,
and so the result is equal to (subreg:VNx8BI x).  Later patches
rely on this.

gcc/
* simplify-rtx.cc (simplify_context::simplify_subreg): Distribute
lowpart subregs through AND/IOR/XOR, if doing so eliminates one
of the terms.
(test_scalar_int_ext_ops): Add some tests of the above for integers.
* config/aarch64/aarch64.cc (aarch64_test_sve_folding): Likewise
add tests for predicate modes.
gcc/config/aarch64/aarch64.cc
gcc/simplify-rtx.cc