https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64700
--- Comment #15 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:c43fed44d9ac34ce88b261cbc0da65e5d3db7132 commit r17-1507-gc43fed44d9ac34ce88b261cbc0da65e5d3db7132 Author: Andrew Pinski <[email protected]> Date: Thu Jun 4 16:09:41 2026 -0700 phiopt: Allow factoring out of more than just single operand operations This takes https://gcc.gnu.org/pipermail/gcc-patches/2026-June/719384.html and merge it into factor_out_conditional_operation. Also expands it to allow for more than just unary and binary operands. It handles as similar as what ifcvt does in factor_out_operators but rejects some cases due to those not being profitable. The cases which are not profitable: * pointer plus in early with constant operand 1 (except if equal). * division/mod with constant operand 1 * Complex expr, it would cause to lose an unitialization warning (gcc.dg/uninit-17.c) some cases needed to be rejected for validity (copied from ifcvt): * BIT_FIELD_REF/BIT_INSERT_EXPR (non first operand) * VEC_PERM_EXPR with constant operand 2 Notes on the testcase changes: The recip-*.c testcases need to be disable phiopt since it removes a division in some cases which causes the recip pass not to run. slsr-12.c and slsr-34.c need to be xfailed. SLSR pass is mostly in maintaince mode and is not getting improved. pr122629-1.c and vect-reduc-cond-2.c are now handled in phiopt rather than ifcvt. cinc_common_1.c is xfailed because of missing pattern in the aarch64 backend, PR112304. fuse_cmp_csel.c needed to be updated since the add is now after the cmp/csel pair and ira puts the constants formation inbetween the cmp/csel. fuse_cmp_csel-1.c is new version where there is no constant formation. changes since v1: * v2: Fix some comments. Add CEIL_MOD_EXPR and ROUND_MOD_EXPR to is_divide_or_mod_p. Remove operand_equal from POINTER_PLUS case. xfail cinc_common_1.c. Fixed up fuse_cmp_csel.c testcase. * v3: Fix up cost model, was only calling is_factor_profitable on the different operands when it needs to be on all operands. * v4: Move is_divide_or_mod_p to tree.h with a rename to int_divide_or_mod_p. Move find_different_opnum to gimple-match-exports.cc/gimple-match.h. PR tree-optimization/125557 PR tree-optimization/64700 PR tree-optimization/29144 PR tree-optimization/94274 gcc/ChangeLog: * tree-if-conv.cc (find_different_opnum): Move to ... * gimple-match-exports.cc (find_different_opnum): Here. * gimple-match.h (find_different_opnum): New decl. * tree-ssa-phiopt.cc (is_factor_profitable): Take gimple_match_op instead of one operand. Rearrange the code to check the lifetime of the operands last. (factor_out_conditional_operation): Handle operands > 1, including operands communitive operands. Add early_p argument for costing. Update call of is_factor_profitable. (pass_phiopt::execute): Pass early_p to factor_out_conditional_operation. * tree.h (int_divide_or_mod_p): New function. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/recip-3.c: Disable phiopt since it removes one division and recip pass needs 3. * gcc.dg/tree-ssa/recip-5.c: Likewise. * gcc.dg/tree-ssa/recip-6.c: Likewise. * gcc.dg/tree-ssa/recip-7.c: Likewise. * gcc.dg/tree-ssa/slsr-12.c: xfail. * gcc.dg/tree-ssa/slsr-34.c: Likewise. * gcc.dg/tree-ssa/pr122629-1.c: Update to scan phiopt1. * gcc.dg/vect/vect-reduc-cond-2.c: Likewise. * gcc.dg/tree-ssa/phi-factor-binary-1.c: New test. * gcc.dg/tree-ssa/phi-factor-binary-2.c: New test. * gcc.target/aarch64/phi-factor-binary-1.c: New test. * gcc.target/aarch64/cinc_common_1.c: xfail. * gcc.target/aarch64/fuse_cmp_csel.c: xfail. * gcc.target/aarch64/fuse_cmp_csel-1.c: New test. Co-authored-by: Kyrylo Tkachov <[email protected]> Signed-off-by: Andrew Pinski <[email protected]>
