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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-07-15
             Target|                            |x86_64-linux-gnu
          Component|middle-end                  |tree-optimization
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, simplified testcase:
```
int tst(unsigned char &x) {
  if (!x) return 8;
  return __builtin_ctz(x);
}

int tst1(unsigned char &x) {
  unsigned t = x;
  t |= 256;
  return __builtin_ctz(t);
}
```


Something like:
```
(simplify
 (cond
  (ne @0 integer_zerop)
  (CTZ (convert@2 @0))
  (INTEGER_CST@1))
 (if (TYPE_UNSIGNED (TREE_TYPE (@0))
      && TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type)
      && wi::to_wide (@1) == TYPE_PRECISION (TREE_TYPE (@0)))
  (CTZ (bit_ior @2 { build_int_cst (1u << (TYPE_PRECISION (TREE_TYPE (@0)) -
1), TREE_TYPE (@2)); }))
```

Note this is not exactly correct as `1u <<` won't work always, need to use
wide_int with the type precision of type.
Also it won't work as phiopt does not handle the extra cast yet.
  • [Bug c++/110679] New: Mis... denis.yaroshevskij at gmail dot com via Gcc-bugs
    • [Bug tree-optimizati... pinskia at gcc dot gnu.org via Gcc-bugs

Reply via email to