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

            Bug ID: 126021
           Summary: 1 >> a is sometimes better than a == 0 on specific
                    types and targets
           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: ---

```
#define type int

type src (type a) {
    if (a >= (sizeof (type) * __CHAR_BIT__))
        __builtin_unreachable ();
    return a == 0;
}

type tgt (type a) {
    return 1 >> a;
}
```

https://godbolt.org/z/zajE6Mrdr
Since r15-6929, tgt is optimize to src.

Compile this with -O3 -march=znver5, using llvm-mca and type = int, tgt uses
one less instruction than src.
  • [Bug target/126021] New: 1 >&... kaelfandrew at gmail dot com via Gcc-bugs

Reply via email to