https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118316

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2025-01-06
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot 
gnu.org

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It comes down to optimizing:
```
unsigned f(unsigned len)
{
  if (len > 1)
    len &= 1;
  return len;
}
```

To just:
  `return len & 1;`

Mine for GCC 16.


phiopt match-simplify trying:
        len_2(D) > 1 ? len_1 : len_2(D)
Matching expression match.pd:2327, gimple-match-5.cc:64

phiopt match-simplify trying:
        len_2(D) <= 1 ? len_2(D) : len_1

len_1 is:
  len_1 = len_2(D) & 1;


Should be just as simple as:
/* `(a > 1) ? (a & 1) : a` -> `a & 1` */
(simplify
 (cond (gt @0 integer_onep) (and@1 @0 integer_onep) @0))
 (if (TREE_UNSIGNED (type))
  @1))

Reply via email to