[Bug tree-optimization/126456] [14/15/16/17 Regression] Wrong code with minmax folding

"pinskia at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126456

Drea Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2026-07-29
     Ever confirmed|0                           |1
   Target Milestone|---                         |14.5
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #1 from Drea Pinski <pinskia at gcc dot gnu.org> ---
```
/* These was part of minmax phiopt.  */
/* Optimize (a CMP b) ? minmax<a, c> : minmax<b, c>
   to minmax<min/max<a, b>, c> */
(for minmax (min max)
 (for cmp (lt le gt ge ne)
  (simplify
   (cond (cmp:c @1 @3) (minmax:c @1 @4) (minmax:c @2 @4))
   (with
    {
      tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3);
    }
    (if (code == MIN_EXPR)
     (minmax (min @1 @2) @4)
     (if (code == MAX_EXPR)
      (minmax (max @1 @2) @4)))))))
```
//(a <= 6) ? (a < c ? a : c) : (5 < c ? 5 : c);
a <= 6 ? min(a,c): min(5,c)
min(c, a <= 6 ? a : 5)

Wait I see the problem, I switched around @2 and @3 arguments to
minmax_from_comparison . The arguments are `arg1 arg2(CMP) arg3 ? arg4 :
arg5`.`
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.