The following patch is for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104971 The PR was already fixed by Jakub but his patch did not fix a latent LRA bug mentioned in the PR comments.  The current patch fixes the latent bug. The patch was successfully bootstrapped and tested on x86-64 and aarch64.