https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126138
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrea Pinski <[email protected]>: https://gcc.gnu.org/g:de8be0eb05d951e93882fe1e66c8d969bb52b4c6 commit r17-2709-gde8be0eb05d951e93882fe1e66c8d969bb52b4c6 Author: Andrea Pinski <[email protected]> Date: Mon Jul 13 15:20:09 2026 -0700 phiopt: New comparison combine part of phiopt [PR126138] Since phiopt rejects trapping statements, this has to be done seperately but it does reuse most of the infastructure to handle this. This is designed to handle foating point comparisons mergining with another one. An example is: ``` c = false; if (a > b) c = a >= b; ``` This should merge into just `c = a > b;`. Which we do already if it was written as `a > b && a >= b`. In this case this is already handled by DOM/VRP/ranger. The case I am more interesting in is: ``` bool f1(double a, double b) { if (a == b) return 1; return a > b; } ``` Which can/should optimize to `a >= b`. This comes from `(a <=> b) >= 0` without spaceship_replacement and/or with a patch that forwprops the phi values into the `>= 0`; replacing the phi. That is this is prerequisite to https://inbox.sourceware.org/gcc-patches/[email protected]/. and to remove spaceship_replacement in phiopt. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/126138 gcc/ChangeLog: * tree-ssa-phiopt.cc (one_feeding_comparison_into_p): New function. (comparison_combine): New function. (pass_phiopt::execute): Call comparison_combine. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/fp-trapping-cmp-4.c: New test. * gcc.dg/tree-ssa/fp-trapping-cmp-5.c: New test. Signed-off-by: Andrea Pinski <[email protected]>
