https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113630
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Note LLVM produces decent code here by only using one load:
> ```
> xor eax, eax
> test esi, esi
> sete al
> mov eax, dword ptr [rdi + 4*rax]
> ```
>
> Maybe GCC could do the same ...
IIRC there's duplicate bugs about this - phiprop does kind-of the reverse.
The sink pass can now sink two exactly same stores but doesn't try sinking
a "compatible" store by introducing a PHI for the address.
/* ??? We could handle differing SSA uses in the LHS by inserting
PHIs for them. */
else if (! operand_equal_p (gimple_assign_lhs (first_store),
gimple_assign_lhs (def), 0)
|| (gimple_clobber_p (first_store)
!= gimple_clobber_p (def)))