https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119884
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Philipp Tomsich <ptoms...@gcc.gnu.org>: https://gcc.gnu.org/g:ec5349c37afe972ee79b777ee749630b1a0a007e commit r16-905-gec5349c37afe972ee79b777ee749630b1a0a007e Author: Konstantinos Eleftheriou <konstantinos.elefther...@vrull.eu> Date: Mon May 19 13:00:05 2025 +0200 asf: Fix calling of emit_move_insn on registers of different modes [PR119884] This patch uses `lowpart_subreg` for the base register initialization, instead of zero-extending it. We had tried this solution before, but we were leaving undefined bytes in the upper part of the register. This shouldn't be happening as we are supposed to write the whole register when the load is eliminated. This was occurring when having multiple stores with the same offset as the load, generating a register move for all of them, overwriting the bit inserts that were inserted before them. In order to overcome this, we are removing redundant stores from the sequence, i.e. stores that write to addresses that will be overwritten by stores that come after them in the sequence. We are using the same bitmap that is used for the load elimination check, to keep track of the bytes that are written by each store. Also, we are now allowing the load to be eliminated even when there are overlaps between the stores, as there is no obvious reason why we shouldn't do that, we just want the stores to cover all of the load's bytes. Bootstrapped/regtested on AArch64 and x86_64. PR rtl-optimization/119884 gcc/ChangeLog: * avoid-store-forwarding.cc (process_store_forwarding): Use `lowpart_subreg` for the base register initialization and remove redundant stores from the store/load sequence. gcc/testsuite/ChangeLog: * gcc.target/i386/pr119884.c: New test.