https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116409
--- Comment #12 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:404d947d8ddd3c3035dcea115e9bab4c4a6bfa1c commit r15-3047-g404d947d8ddd3c3035dcea115e9bab4c4a6bfa1c Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Sun Aug 18 20:45:35 2024 -0700 phi-opt: Fix for failing maybe_push_res_to_seq in factor_out_conditional_operation [PR 116409] The code was assuming that maybe_push_res_to_seq would not fail if the gimple_extract_op returned true. But for some cases when the function is pure rather than const, then it can fail. This change moves around the code to check the result of maybe_push_res_to_seq instead of assuming it will always work. Changes since v1: * v2: Instead of directly testing non-pure builtin functions change to test if maybe_push_res_to_seq fails. Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/116409 gcc/ChangeLog: * tree-ssa-phiopt.cc (factor_out_conditional_operation): Move maybe_push_res_to_seq before creating the phi node and the debug dump. Return false if maybe_push_res_to_seq fails. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr116409-1.c: New test. * gcc.dg/torture/pr116409-2.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>