https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128997
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:5ea58c9d725146c20854720dba46175add86bac6 commit r17-6700-g5ea58c9d725146c20854720dba46175add86bac6 Author: Jeff Law <[email protected]> Date: Wed Nov 25 13:39:42 2026 -0700 [PR rtl-optimization/pr128997] Clear SUBREG_PROMOTED after copy propagation into a SUBREG Another fun bug... This was bisected to a change which flipped logical op short circuiting on the RISC-V port, but that's just the event that exposed the latent cse (again!) bug. CSE is propagating a copy into a SUBREG expression where the SUBREG is marked with promotion state. Promotion state is effectively a global state for each pseudo -- if we have (subreg (reg ...)) with promoted state on the SUBREG, then we assume that the reg is always properly extended. That assumption is baked into nonzero_bits, num_sign_bit_copies and perhaps other places. When we do copy propagation we have to make sure that the replacement honors those assumptions or we need to clear the promotion state. In this case we can adjust the SUBREG to drop the promoted state when the transformation is made. Assisted-by: Claude for analysis of dump files to figure out where things went wrong. Bootstrapped and regression tested on x86_64 and aarch64. Light testing on rv64 as well. I'll wait for Sashiko's review before pushing. PR rtl-optimization/128997 gcc/ * cse.cc (canon_reg): Clear SUBREG_PROMOTED_VAR_P after substituting into a SUBREG expression. gcc/testsuite * gcc.dg/torture/pr128997.c: New test.
