https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128641
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:210ff013a2e14b94d0b3e5e645ab6b69847e06ef commit r17-6495-g210ff013a2e14b94d0b3e5e645ab6b69847e06ef Author: Kyrylo Tkachov <[email protected]> Date: Thu Nov 19 04:44:22 2026 -0800 tree-optimization/128641 - predcom initializers must be TBAA-equivalent This follows up the previous PR128641 change addressing the Sashiko concern. The same problem exists for looparound initializers. pcom_worker::valid_initializer_p accepts the preheader load that feeds a looparound PHI as the initial value of a chain without checking that it behaves like the chain root for TBAA. The check in find_looparound_phi that nothing clobbers the initializer between its definition and the loop entry queries the alias set of the initializer, not that of the chain root. The chain then replaces the in-loop load of the root alias set at iteration 0 with the stale value: prev = *(long long *) b; // initializer f (b); // writes only long, TBAA-disjoint from above loop: cur = *(long *) (b + 8 + k * 8); s += *(long *) (b + k * 8); // iteration 0 must see the value from f t += prev; prev = cur; Require the initializer and the chain root to behave the same for TBAA in both directions in valid_initializer_p. Factor the check shared with determine_offset into refs_tbaa_equivalent_p. The check is symmetric, so it also covers a later reordering of the initializer load. Bootstrapped and tested on aarch64-none-linux-gnu. gcc/ChangeLog: PR tree-optimization/128641 * tree-predcom.cc (refs_tbaa_equivalent_p): New. (pcom_worker::determine_offset): Use it. (pcom_worker::valid_initializer_p): Also require the initializer and ROOT to be TBAA-equivalent. gcc/testsuite/ChangeLog: PR tree-optimization/128641 * gcc.dg/torture/pr128641-3.c: New test. * gcc.dg/torture/pr128641-4.c: Likewise. * gcc.dg/torture/pr128641-5.c: Likewise. Signed-off-by: Kyrylo Tkachov <[email protected]>
