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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement
            Summary|Missed optimization: fold   |Missed optimization: fold
                   |`3 / (b ^ a)` to `b < 4`    |`(a^b) <= 3` to `b < 4` for
                   |                            |bool a and know that (a^b)
                   |                            |is non zero
   Last reconfirmed|                            |2024-06-08
          Component|c++                         |tree-optimization
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. Note GCC already transform `3 / (b ^ a)` into `(a^b) <= 3`. But does
not transform that into `b <= 3` when we know that `a` has a [0,1] range.


A simple pattern like:
```
(for cmp (gt le)
 (simplify
  (cmp:c (bit_xor @0 zero_one_valued_p@1) INTEGER_CST@2)
  (if ((wi::to_wide (2) & 1) == 1)
   (cmp @0 @2)))
```
Should work.

Note this can be expanded into more if needed

Reply via email to