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

            Bug ID: 127012
           Summary: Missed X86 optimization of or to use lea when x < CST
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kaelfandrew at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/EKszhKeE6

```c
#define TYPE unsigned
#define N 4
#define CST ((TYPE)1 << N)

TYPE
src (TYPE x)
{
  if (x >= CST)
    __builtin_unreachable ();
  return x | CST;
}
```

With -O2, GCC produce this assembly:
```
"src":
        mov     eax, edi
        or      eax, 16
        ret
```

While Clang -O2:
```
src:
        lea     eax, [rdi + 16]
        ret
```

Clang on x86_64 does this for TYPEs u8, u32, u64, u128.

Reply via email to