]> git.ipfire.org Git - thirdparty/gcc.git/commit
simplify-rtx: Canonicalize SUBREG and LSHIFTRT order for AND operations
authorKishan Parmar <kishan@linux.ibm.com>
Tue, 4 Nov 2025 07:11:28 +0000 (12:41 +0530)
committerKishan Parmar <kishan@linux.ibm.com>
Tue, 4 Nov 2025 07:13:13 +0000 (12:43 +0530)
commita50b4406e5d64adb6bb0ebde3710f6742a0bdbed
treea6697c96b74bb4c9c3b0889d39069676559210de
parent0a2c4b6dd2019d144df49227fce950e10ae62b09
simplify-rtx: Canonicalize SUBREG and LSHIFTRT order for AND operations

For a given rtx expression (and (lshiftrt (subreg X) shift) mask)
combine pass tries to simplify the RTL form to

   (and (subreg (lshiftrt X shift)) mask)

where the SUBREG wraps the result of the shift.  This leaves the AND
and the shift in different modes, which complicates recognition.

   (and (lshiftrt (subreg X) shift) mask)

where the SUBREG is inside the shift and both operations share the same
mode.  This form is easier to recognize across targets and enables
cleaner pattern matching.

This patch checks in simplify-rtx to perform this transformation when
safe: the SUBREG must be a lowpart, the shift amount must be valid, and
the precision of the operation must be preserved.

Tested on powerpc64le-linux-gnu, powerpc64-linux-gnu, and
x86_64-pc-linux-gnu with no regressions.  On rs6000, the change reduces
insn counts due to improved matching.

2025-11-04  Kishan Parmar  <kishan@linux.ibm.com>

gcc/ChangeLog:

PR rtl-optimization/93738
* simplify-rtx.cc (simplify_binary_operation_1): Canonicalize
SUBREG(LSHIFTRT) into LSHIFTRT(SUBREG) when valid.

gcc/testsuite/ChangeLog:

PR rtl-optimization/93738
* gcc.target/powerpc/rlwimi-2.c: Update expected rldicl count.
gcc/simplify-rtx.cc
gcc/testsuite/gcc.target/powerpc/rlwimi-2.c