On 10/30/25 9:06 AM, Kishan Parmar wrote:
Hi All,

Changes from v3:
        * Replace GET_CODE (op) == SUBREG with SUBREG_P (op).
Changes from v2:
        * Code refactoring.
Changes from v1:
        * Corrected commit message.

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-10-29  Kishan Parmar  <[email protected]>

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.
OK. You've got commit access, so go ahead and commit when it's convenient for you.

Jeff

Reply via email to