https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126896
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Aldy Hernandez <[email protected]>: https://gcc.gnu.org/g:804ff22702eca4e389e1a2f3659010190504a757 commit r17-3622-g804ff22702eca4e389e1a2f3659010190504a757 Author: Aldy Hernandez <[email protected]> Date: Sat Aug 22 10:48:46 2026 +0000 phiopt: replicate conditionals over a PHI of comparisons [PR126896] DOM's jump threader duplicates a join block that merges comparisons into a boolean that is immediately tested: <bb 3>: t_9 = a < b; goto <bb 5>; <bb 4>: t_6 = c < d; goto <bb 5>; <bb 5>: # t_1 = PHI <t_9(3), t_6(4)> if (t_1 != 0) Implement this optimization in the phiopt pass, without using the jump threading machinery DOM's version uses. This was an optimization we lost with the jump threader rewrite, which DOM ended up picking up. Measured over GCC's own sources plus LAPACK, the phiopt version takes over ~94% of the joins DOM's special case caught: DOM registrations for this optimization drop from 3536 to 196, with 1325 phiopt replications; the remainder are cases that show up between phiopt and DOM. Optimizations at loop boundaries (approx 700) are deliberately left to the DOM threader, as replicating those would change loop structure. I could loosen this restriction, but I've learned to fear all things loop ;-). I've left DOM's version in place, just in case we still want to allow it for loop things, but I can just as easily drop it in a follow-up patch. Tested on ppc64le Linux. PR tree-optimization/126896 gcc/ChangeLog: * tree-ssa-phiopt.cc: Include tree-ssa-threadedge.h. (preserves_loop_structure_p): New. (replicate_cond_into_pred): New. (replicate_conds_over_phis): New. (pass_phiopt::execute): Call replicate_conds_over_phis. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi_on_compare-1.c: Scan the phiopt2 dump. * gcc.dg/tree-ssa/phi_on_compare-2.c: Scan the optimized dump. * gcc.dg/tree-ssa/phi_on_compare-3.c: Likewise. * gcc.dg/tree-ssa/dom-jump-threading-1.c: Disable phiopt. * gcc.dg/tree-ssa/dom-jump-threading-2.c: Likewise. * gcc.dg/tree-ssa/phi_on_compare-5.c: New test.
