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.