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

            Bug ID: 127368
           Summary: Missed optimization of 1 << ctz (lhs) --> lhs & -lhs
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaelfandrew at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/nfEqer7vT

With -O2, GCC does not optimize src1/src2 to tgt1/tgt2 that clang
optimize:

```
unsigned
src1 (unsigned lhs)
{
  return 1 << __builtin_ctzg (lhs);
}

unsigned
tgt1 (unsigned lhs)
{
  return (lhs & -lhs);
}

unsigned
src2 (unsigned lhs, unsigned rhs)
{
  return (lhs << __builtin_ctzg (rhs));
}

unsigned
tgt2 (unsigned lhs, unsigned rhs)
{
  return (rhs & -rhs) * lhs;
}
```
  • [Bug tree-optimization/127368] N... kaelfandrew at gmail dot com via Gcc-bugs

Reply via email to