https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127039
--- Comment #4 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:67dfeda6483525262abbd26a0789672dfa9a0a33 commit r17-3608-g67dfeda6483525262abbd26a0789672dfa9a0a33 Author: Kyrylo Tkachov <[email protected]> Date: Mon Aug 24 17:21:36 2026 +0200 match.pd: avoid a reduction simplification cycle [PR127039] The reduction-of-a-constant rule can change REDUC (V op C) into REDUC (V) op REDUC (C). The reduction-pair rule can then combine the result back into the original form. For a scalable vector, REDUC (C) might not fold because the number of lanes is not constant. The two rules then alternate during forwprop and keep adding dead statements until the compiler exhausts memory. Split the six reductions that have an inverse pair rule from FMAX and FMIN, which do not. Mark the constant reduction in the first group with `!`. The first transformation now succeeds only when REDUC (C) simplifies to a scalar operand. The result cannot match the inverse reduction-pair rule. Keep the FMAX and FMIN transformation unchanged. Bootstrapped and tested on aarch64-unknown-linux-gnu and confirmed with a riscv cross that the OOM does not happen. gcc/ChangeLog: PR tree-optimization/127039 * match.pd (REDUC (@0 op VECTOR_CST)): Require the constant reduction to simplify. gcc/testsuite/ChangeLog: PR tree-optimization/127039 * gcc.dg/pr127039.c: New test. Signed-off-by: Kyrylo Tkachov <[email protected]>
