https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116699
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:6e4244e8ceac939fe8a24470b4ff31c82e8bff21 commit r15-3648-g6e4244e8ceac939fe8a24470b4ff31c82e8bff21 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Fri Sep 13 10:47:29 2024 -0700 phi-opt: Improve heuristics for factoring out with constant (again) [PR116699] The heuristics for factoring out with a constant checks that the assignment statement is the last statement of the basic block but sometimes there is a predicate or a nop statement after the assignment. Rejecting this case does not make sense since both predicates and nop statements are removed and don't contribute any instructions. So we should skip over them when checking if the assignment statement was the last statement in the basic block. phi-opt-factor-1.c's f0 is such an example where it should catch it at phiopt1 (before predicates are removed) and should happen in a similar way as f1 (which uses a temporary variable rather than return). Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116699 gcc/ChangeLog: * tree-ssa-phiopt.cc (factor_out_conditional_operation): Skip over nop/predicates for seeing the assignment is the last statement. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-factor-1.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>